-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include sealed traits and classes as elements of Sum Mirrors #11851
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick fix!
@@ -95,7 +95,7 @@ object SymUtils: | |||
* - none of its children are anonymous classes | |||
* - all of its children are addressable through a path from the parent class | |||
* and also the location of the generated mirror. | |||
* - all of its children are generic products or singletons | |||
* - all of its children are generic products, singletons, or sealed traits ar classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* - all of its children are generic products, singletons, or sealed traits ar classes | |
* - all of its children are generic products, singletons, or sealed traits or classes |
|
||
@main def Test = | ||
summon[Mirror.Of[A]] | ||
summon[Mirror.Of[B]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maybe add another test like the following?
val mirrorA = summon[Mirror.Of[A]]
summon[mirrorA.MirroredElemTypes <:< (C *: B *: EmptyTuple)]
As the failure of the Akka CB shows, I have overlooked something. The trait hierarchy can be an arbitrary graph. Consider: sealed trait A
sealed trait B extends A
sealed trait C extends A
case class D() extends B, C
case class E() extends B, C Now if we generate the ordinal method, we get unreachable cases. That's what we observe when trying to build akka. I see currently three ways to address this:
|
Which assumptions do you think about? |
For instance, if I have typeclass derivation code that consults the children annotation at runtime I get a mismatch between that and what the mirror claims. Or if the code assumes that all mirror elements have the sum as direct parent type. |
(Dale is OOO this week) |
I'm happy to put my hand up for that. Let me know what you need! |
Regarding the approach to implementation, I have another one to add to the 3 ideas above. (4) Have two means of summoning a mirror, both with simple algorithms:
summon[Mirror.Of[A]].MirroredElemTypes =:= (C, D)
summon[Mirror.Of[B]].MirroredElemTypes =:= (D)
summon[Mirror.DirectlyOf[A]].MirroredElemTypes =:= (B, C, D)
summon[Mirror.DirectlyOf[B]].MirroredElemTypes =:= (D) In my experience with automatic derivation, it's always one of the above two I want. Which one depends on what I'm deriving. |
@japgolly Interesting. I’m not sure whether we can change this now but I agree with your analysis: those two ways of retrieving the subclasses are the most common in my experience as well. |
I think it's probably best for now to continue with #11686. But since Dale is OOO this weak there's no chance for it to make it into RC2. In my opinion, even if we could work on this right now, it would be too big a change to make so short before the release date. |
Addresses feature request #161
lampepfl/dotty-feature-requests#161
This is just the immediate fix. We need more tests and use cases to see whether it works. @dwijnand if we can get some corrobation by Wednesday we might be able to roll this into 3.0. Otherwise it will have to wait.