pattern-matching a recursive type - "error during expansion of this match (this is a scalac bug)" #13063
Labels
fixed in Scala 3
This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
patmat
Milestone
Reproduction steps
Scala version: 2.13.15
JVM 17
openjdk version "17.0.8.1" 2023-08-24 LTS, OpenJDK Runtime Environment Zulu17.44+53-CA (build 17.0.8.1+1-LTS)
Running on MacBook (Intel)
Compile this Scala code:
Result: compilation in Scala 2.13.15 fails with an error:
There is no failure with Scala 3.3.1 or 3.4.1.
Problem
The pattern-matching code is expected to be valid Scala, because this looks like a straightforward ADT.
The pattern-matching code as shown can be compiled as long as the depth is not more than 3 nested case classes. The pattern match fails to compile whenever the pattern is deep enough (at least 4 nested case classes or more). In the example shown above, the pattern match on
Fix(Branch(Fix(_)...
compiles but the patternFix(Branch(Fix(Leaf(_)...
fails to compile.The compilation failure occurs with Scala 2.13 but not with Scala 3. (I tested Scala 3.3.1 and Scala 3.4.1.)
There is a possibly related issue #9446 but that issue involves an existential type and no deeply-nested patterns.
The text was updated successfully, but these errors were encountered: