-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix #10511: compare enumvalues in provably disjoint #10938
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
fix #10511: compare enumvalues in provably disjoint #10938
Conversation
a6b174c
to
6676d14
Compare
6676d14
to
3202767
Compare
I have also tested transitivity of passing aliases to singleton enum values, such as this: val t: True.type = True
val f: False.type = False
val t1: Not[f.type] = t // transitivity
val f1: Not[t.type] = f // transitivity Edit: this has been prevented from running in the FromTasty test due to aparrently different reduction of match types with that option |
fc55b9a
to
7377ee3
Compare
case False.type => True.type | ||
} | ||
|
||
def not[B <: Bool & Singleton](b: B): Not[B] = b match { |
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's nice that Singleton
helps inference here, the following compiles as expected:
not(True): False.type
Although it's a bit fragile:
val vrais = True
not(vrais): False.type // error, we lost the singleton type...
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.
yeah its true with enums a user must do a lot of work to avoid the widening but thats something hopefully we can tune based on feedback without ruining bincompat
I think this PR should also update the docs, the diff LGTM otherwise. It wouldn't be sounds to compare singleton types in the general case, but as far as I can tell it's fine to do for enums because value cases are guaranteed to point to a different object. |
I've updated the match-types doc |
so FromTastyTest for |
it is possible to get the def isEnumValueOrModule(ref: TermRef): Boolean =
val sym = ref.termSymbol
sym.isAllOf(EnumCase, butNot=JavaDefined)
|| sym.is(Module)
|| (sym.info.normalized match
case tp: TermRef => isEnumValueOrModule(tp)
case tp => false) or get |
this also shortcuts comparing
object
refs without looking at their supertypefixes #10511