-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enum Value singleton fails to reduce in match type #10511
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
Comments
That's not very surprizing given that this enum doesn't create new types for its cases, just vals. The question here is what's the meaning of the patterns in the following example:? def not[B <: Bool](b: B) = b match {
case _: True.type => False.type
case _: False.type => True.type
} Given that |
I think this is another example that shows that users don't read the enum spec and are surprised by the differences between |
@OlivierBlanvillain matching on singleton types becomes a test on identity with |
Yes my bad, but in the general case there is no way to statically conclude that sealed trait Bool
object Bool {
val True = new Bool
val False = True
} |
@OlivierBlanvillain all symbols of enum value definitions will also have the |
@OlivierBlanvillain @bishabosha Not sure where we are with this. Is there a concrete action item? if not please close. |
Even if what @bishabosha suggests is technically feasible, I think that it would a deviation from the current design of enums and match types. An enum defines values, not types, so from an ideological standpoint, users interested in doing type-level programming should defines their types using traits and classes, not enums. |
I am confused about this point, all we already have a case in the Inliner to support treating enum values as defining a unique type, used in inline match: |
The meaning of Enum were designed to be a desugaring step which makes them super simple; if we have to special case the type checker at every corner to handle enums we lose some of that simplicity. I'm not saying we shouldn't do it, but it falls into the needs-spec/feature-request category. (Feel free to reopen if you're not convinced, I don't want to impose my views!) |
@odersky I will reopen due to the linked PR #10938 which enables the snippet in this issue to compile. I agree that not having a new backing class for each singleton enum value causes some friction but then again I fail to see why we could promote enum as a drop in replacement if it were not able to participate in the key metaprogramming advances of Scala 3. |
fix #10511: compare enumvalues in provably disjoint
Uh oh!
There was an error while loading. Please reload this page.
Minimised Code
Output
Expectation
if I replace
enum Bool
with a sealed trait and case objects then the code compiles:Originally posted by @bishabosha in #10510 (comment)
The text was updated successfully, but these errors were encountered: