Skip to content

Missing unchecked warning when pattern matching on a type parameter #1828

Closed
@jedesah

Description

@jedesah
def remove[S](a: S | Int, f: Int => S):S = a match {
  case a: S => a
  case a: Int => f(a)
}

val t: Int | String = 5
val t1 = remove[String](t, _.toString)

This compiles fine, but at runtime, the call to remove will throw a java.lang.ClassCastException (Integer cannot be cast to String)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions