Closed
Description
The minimized code below compiles in Scala 3.3.1 but is failing in Scala 3.4.0-RC1. Is this a bug or an expected behaviour in Scala 3.4.0? If yes, is there any workaround for this?
trait Foo:
case class Bar[A](value: A)
object FooBar extends Foo
type UnwrapTypes[Xs] =
Xs match
case EmptyTuple => Xs
case x *: xs => UnwrapTypes[x] *: UnwrapTypes[xs]
case Foo#Bar[x] => UnwrapTypes[x]
case String => String
case Int => Int
val x: Int = ??? : UnwrapTypes[FooBar.Bar[Int]]
val tup: (Int, String) = ??? : UnwrapTypes[(FooBar.Bar[Int], FooBar.Bar[String])]
Output
[info] compiling 1 Scala source to /home/chungonn/development/experiments/scala3-types-match/target/scala-3.4.0-RC1/classes ...
[error] -- [E007] Type Mismatch Error: /home/chungonn/development/experiments/scala3-types-match/src/main/scala/matchtypes/Main.scala:16:13
[error] 16 |val x: Int = ??? : UnwrapTypes[FooBar.Bar[Int]]
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |Found: matchtypes.UnwrapTypes[matchtypes.FooBar.Bar[Int]]
[error] |Required: Int
[error] |
[error] |Note: a match type could not be fully reduced:
[error] |
[error] | trying to reduce matchtypes.UnwrapTypes[matchtypes.FooBar.Bar[Int]]
[error] | failed since selector matchtypes.FooBar.Bar[Int]
[error] | does not match case matchtypes.Foo#Bar[x] => matchtypes.UnwrapTypes[x]
[error] | and cannot be shown to be disjoint from it either.
[error] | Therefore, reduction cannot advance to the remaining cases
[error] |
[error] | case String => String
[error] | case Int => Int
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] -- [E007] Type Mismatch Error: /home/chungonn/development/experiments/scala3-types-match/src/main/scala/matchtypes/Main.scala:17:26
[error] 17 |val tup: (Int, String) = ??? : UnwrapTypes[(FooBar.Bar[Int], FooBar.Bar[String])]
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |Found: (matchtypes.UnwrapTypes[matchtypes.FooBar.Bar[Int]],
[error] | matchtypes.UnwrapTypes[matchtypes.FooBar.Bar[String]])
[error] |Required: (Int, String)
[error] |
[error] |Note: a match type could not be fully reduced:
[error] |
[error] | trying to reduce matchtypes.UnwrapTypes[matchtypes.FooBar.Bar[Int]]
[error] | failed since selector matchtypes.FooBar.Bar[Int]
[error] | does not match case matchtypes.Foo#Bar[x] => matchtypes.UnwrapTypes[x]
[error] | and cannot be shown to be disjoint from it either.
[error] | Therefore, reduction cannot advance to the remaining cases
[error] |
[error] | case String => String
[error] | case Int => Int
[error] |
[error] | longer explanation available when compiling with `-explain`
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed