-
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
Synthesise Mirror.Sum for nested hierarchies #11686
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have minimised the Akka failure: package akka.event
sealed trait LogEvent
object LogEvent
case class Error() extends LogEvent
class Error2() extends Error() with LogEventWithMarker
case class Warning() extends LogEvent
sealed trait LogEventWithMarker extends LogEvent this generates the following warning:
the warning comes from the ordinal method, which looks like the following: object LogEvent extends scala.deriving.Mirror.Sum {
type MirroredMonoType = akka.event.LogEvent
def ordinal(x: akka.event.LogEvent.MirroredMonoType): Int = x match
case _:akka.event.Error => 0
case _:akka.event.Warning => 1
case _:akka.event.LogEventWithMarker => 2
} The only instance of |
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.
the code gen for cases in the ordinal
method needs to take into account multiple inheritance with traits
https://github.com/lampepfl/dotty/blob/a956774180d124adc98527863b919c35d5f9db92/compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala#L519
this is more strange, if we delete the def ordinal(x$0: akka.event.LogEvent.MirroredMonoType): Int = x$0 match
case _:akka.event.Error => 0
case _:akka.event.LogEventWithMarker => 1 but in this case we get no warning? cc/@liufengyun |
its worth noting also that in this formulation, there is no warning as package akka.event
sealed trait LogEvent
object LogEvent
sealed trait LogEventWithMarker extends LogEvent
case class Error() extends LogEvent
class Error2() extends Error() with LogEventWithMarker
case class Warning() extends LogEvent this means |
Could you report a bug? I can have a look. |
a220938
to
3665eba
Compare
Just re-force pushed to make sure the test case correctly reproduces your findings. After trying different things I came to the conclusion that the "class extends case class" pattern should fail the sum/product game for the mirror, keeping things simple: that case isn't a part of the motivating use cases, and it only came up because they were failing to generate mirrors without warnings. So I think this is good now, multi-level sealed traits now get sum mirrors without breaking the community projects. |
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.
It looks great apart from the comment about the declScope
argument to whyNotGenericSum
.
I have put this for 3.1 because some companion objects will now get |
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.
This PR still needs to update the ordinal
method in SyntheticMembers
,
the following will generate the "unreachable case" warning due to generating a branch for Bottom
in the ordinal
sealed trait Top
object Top
final case class MiddleA() extends Top with Bottom
final case class MiddleB() extends Top with Bottom
final case class MiddleC() extends Top with Bottom
sealed trait Bottom extends Top
-- [E030] Match case Unreachable Warning: sandbox/mirrors/example.scala:2:7 ----
2 |object Top
| ^
| Unreachable case
1 warning found
... the generated ordinal mirror method here:
def ordinal(x$0: MirroredMonoType): Int = x$0 match
case _:MiddleA => 0
case _:MiddleB => 1
case _:MiddleC => 2
case _:Bottom => 3 // this case can't be reached
@bishabosha WDYT about just suppressing that? The fact that It's also a much easier fix but I can't tell how much my thinking above is biased by that... |
I think it would be fine to just add |
Might've been easier than I thought: #13414. |
Fixes lampepfl/dotty-feature-requests#161
aka https://github.com/lampepfl/dotty/issues/11050