"java.lang.ClassCastException" due to compiler doesn't generate error "Covariant type T occurs in contravariant position in type T of value element" for private members" #18676
Labels
area:refchecks
area:typer
itype:bug
itype:soundness
Soundness bug (it lets us compile code that crashes at runtime with a ClassCastException)
Compiler version
Scala 3.3.1
Minimized code
Output
The code compiles, but when you run the program it crashes with error
Exception in thread "main" java.lang.ClassCastException: class Cat cannot be cast to class Dog (Cat and Dog are in unnamed module of loader 'app') at Wrapper$.main(Animal.scala:12) at Wrapper.main(Animal.scala)
Expectation
The code compiles in Scala 3 but didn't compile in 2.13.
It should produce error
Covariant type T occurs in contravariant position in type T of value element
The compiler shouldn't produce the error only when the visibility is
private[this]
.It looks like there is a typo somewhere in the compiler which checks for
private
, notprivate[this]
Related issue in The Scala Plugin, which actually shows the error:
https://youtrack.jetbrains.com/issue/SCL-21676
The text was updated successfully, but these errors were encountered: