-
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
Match type upper bounds lead to unexpected compiler behavior #15816
Labels
Comments
Bersier
added
itype:bug
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Aug 3, 2022
WojciechMazur
added
area:typer
and removed
stat:needs triage
Every issue needs to have an "area" and "itype" label
labels
Aug 4, 2022
I managed to minimize the code further (it should also be easier to follow): sealed trait NatT
final case class Zero() extends NatT
final case class Succ[+N <: NatT](n: N) extends NatT
type ZeroAndSecondNat[X <: NatT, Y <: Succ[NatT]] <: (NatT, NatT) = Y match
case Succ[_] => (_0, Y)
type Second[P] = P match
case (_, y) => y
type SecondNat[X <: NatT, Y <: Succ[NatT]] = Second[ZeroAndSecondNat[X, Y]]
type SecondNat2[X <: NatT, Y <: Succ[NatT]] <: NatT = ZeroAndSecondNat[X, Y] match
case (_, y) => y
@main def main(): Unit =
_2: Second[ZeroAndSecondNat[_1, _2]] // No error, as expected.
_2: Second[ZeroAndSecondNat[_1, _1]] // Error, as expected.
_2: SecondNat[_1, _1] // No error, unexpected.
_2: SecondNat2[_1, _2] // Error, unexpected.
type _0 = Zero
type _1 = Succ[_0]
type _2 = Succ[_1]
val _0: _0 = Zero()
val _1: _1 = Succ(_0)
val _2: _2 = Succ(_1) @dwijnand Is that small enough? |
Yep, thank you. |
Likely the same cause as #15926. |
I tried this with Scala 3.4.0-RC4, and the minimized code now behaves as expected. However, the original code still behaves oddly. Here is some new minimized code: sealed trait NatT
final case class Zero() extends NatT
final case class Succ[+N <: NatT](n: N) extends NatT
type NatDiv[X <: NatT, Y <: Succ[NatT]] <: (NatT, NatT) = Y match
case _1 => (X, _0)
case _ => (_1, _1)
type NatRem2[X <: NatT, Y <: Succ[NatT]] = NatDiv[X, Y] match
case (_, y) => y
@main def main(): Unit =
_1: NatRem2[_3, _2] // Error, unexpected.
type _0 = Zero
type _1 = Succ[_0]
type _2 = Succ[_1]
type _3 = Succ[_2]
val _0: _0 = Zero()
val _1: _1 = Succ(_0) The compiler error:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler version
3.1.3
Minimized code
Output
See here.
The unexpected error for
_1: NatRem2[_3, _2]
:Expectation
Removing the type bounds from the match type definitions fixes the unexpected errors or lack thereof. It is unexpected that the behavior of the code should change based on redundant type bounds. Moreover, the error messages seem misleading at best. See this thread.
The text was updated successfully, but these errors were encountered: