Skip to content

catch case fails to warn in case of unchecked bounded type parameter #19013

Closed
@scf37

Description

@scf37

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?).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions