"Ill-scoped" type variables can be bound in patterns #16952
Labels
area:typer
itype:bug
itype:soundness
Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)
Compiler version
Dotty 3.2.2 on Scastie as well as Dotty 3.3.0-RC3 locally. Seems to exist from Scala 2.
Minimized code
Output
Compiles.
Expectation
Type error at the pattern
y: T[T[a]]
, which should not be allowed in a match on a value of typeT[T[_]]
. Conceptually, the pattern just doesn't make sense. (What isa
supposed to be binding? It's clear forx: T[_]
, but not forx: T[T[_]]
.) In a less minimal case of the same kind of pattern, there is an unsoundness:This case gives a
ClassCastException
at runtime, since the bad pattern is not stopped at compile-time.The text was updated successfully, but these errors were encountered: