-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:inlinearea:typeritype:bugitype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)
Description
Compiler version
3.7.4
3.8.1-RC1-bin-20251215-a227106-NIGHTLY
Minimized code
import scala.compiletime.erasedValue
object Test {
type MatchType[T] = T match {
case EmptyTuple => String
case _ => Int
}
trait MyTrait[T] {
def f: MatchType[T]
}
class MyClass[T] extends MyTrait[T] {
override inline def f: MatchType[T] = inline erasedValue[T] match {
case _: EmptyTuple => "empty"
case _ => 42
}
}
@main def main(): Unit = {
val a: MyTrait[EmptyTuple] = new MyClass[EmptyTuple]
val str: String = a.f
}
}
Output
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
at Test$.main(overrideInline.scala:22)
at main.main(overrideInline.scala:20)Expectation
Should not compile
Metadata
Metadata
Assignees
Labels
area:inlinearea:typeritype:bugitype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)