-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
area:desugarDesugaring happens after parsing but before typing, see desugar.scalaDesugaring happens after parsing but before typing, see desugar.scalaitype: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)
Milestone
Description
Compiler version
Scala CLI version: 1.5.4
Scala version (default): 3.5.2
Minimized code
def boundary[T](body: (T => RuntimeException) => T): T =
case class Break(value: T) extends RuntimeException
try body(Break.apply)
catch case Break(t) => t
@main def main =
boundary[Int]: EInt =>
val v: String = boundary[String]: EString =>
throw EInt(3)
v.length
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 crash$package$.main$$anonfun$1(crash.scala:8)
at crash$package$.boundary(crash.scala:3)
at crash$package$.main(crash.scala:7)
at main.main(crash.scala:6)
Expectation
The program should either be rejected at compilation, or not crash. The problem seems to be that there's only one Break
class at runtime, but the typechecker thinks that Break
must contain a T
.
Metadata
Metadata
Assignees
Labels
area:desugarDesugaring happens after parsing but before typing, see desugar.scalaDesugaring happens after parsing but before typing, see desugar.scalaitype: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)