-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Match types combined with GADT pattern match not reducing as expected #10510
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
minimised to enum Bool {
case True
case False
}
import Bool._
type Not[B <: Bool] = B match {
case True.type => False.type
case False.type => True.type
}
val f: Not[False.type] = True 13 |val f: Not[False.type] = True
| ^^^^
| Found: (Bool.True : Bool)
| Required: Not[(Bool.False : Bool)] |
in this case, it seems that the singleton type of enum values is treated differently to the singleton type of objects, e.g. this works: sealed trait Bool
object Bool {
case object True extends Bool
case object False extends Bool
}
import Bool._
type Not[B <: Bool] = B match {
case True.type => False.type
case False.type => True.type
}
val f: Not[False.type] = True |
Writing |
yes, what I found seems to be another issue :/ |
Can this issue be minimized without enums? Match types on See my comments in #10511 |
Could you suggest how I can change the example in my initial post to fix the issue? You are saying that type Not[B <: Bool] = B match {
case True.type => False.type
case False.type => True.type
} will not work well because I used an |
Yes, I meant using traits and classes instead of enums to try to pin point the issue, like this: sealed trait Bool
case object True extends Bool
case object False extends Bool
sealed trait SBool[B <: Bool]
case object STrue extends SBool[True.type]
case object SFalse extends SBool[False.type]
type Not[B <: Bool] <: Bool = B match {
case True.type => False.type
case False.type => True.type
}
def not[B <: Bool](b: SBool[B]): SBool[Not[B]] = b match {
case STrue => SFalse
case SFalse => STrue
} That minimization seems to be a duplicate #6687. |
Ooh I see now, your comment was about minimization of the example. Yes that might aid in debugging it. |
Uh oh!
There was an error while loading. Please reload this page.
Minimized code
Output
Expectation
I would expect the
not
function to pass typechecking, but it doesn't. Interestingly if I add aimplicitly[Not[B] =:= False.type]
in the first branch ofnot
it will not complain, so it does know thatB
is actuallyTrue.type
in that branch and it will reduceNot
correctly if I ask for it.It looks like the types are not reduced enough when checking the type of the branches against the return type of the function (
not
).The text was updated successfully, but these errors were encountered: