-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
SpreeSuitable for a future SpreeSuitable for a future Spreearea:pattern-matchingarea: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.3.1
Minimized code
def handle[E <: Exception](f: => Unit): Option[E] =
try
f
None
catch case e: E => Some(e)
val r: RuntimeException = handle[RuntimeException](throw new Exception()).get
Output
java.lang.ClassCastException: class java.lang.Exception cannot be cast to class java.lang.RuntimeException (java.lang.Exception and java.lang.RuntimeException are in module java.base of loader 'bootstrap')
Expectation
Fail compilation because type of E is not known in compile time, allow compilation for inline method (or maybe also by ClassTag in scope?).
SethTisue
Metadata
Metadata
Assignees
Labels
SpreeSuitable for a future SpreeSuitable for a future Spreearea:pattern-matchingarea: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)