-
Couldn't load subscription status.
- Fork 1.1k
Closed
Labels
area:pattern-matchingitype: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
trait Foo[X >: Any <: Nothing]
@main def Test = (None: Option[Foo[?]]) match {
case _: Option[Foo[t]] =>
val unsound: Nothing = (5 : Any) : t
(unsound : Unit => Unit).apply(())
}The problem seems to be that pattern matching lets us name a type argument which does not correspond to a type member with known good bounds. In DOT, we would not be able to refer to t, so the issue would not show up.
Fixes we have thought of so far:
- Disallowing classes with bad bounds on type parameters
- Disallowing pat-mat from naming types with bad bounds / only letting pat-mat name types with bounds that are known to be good
- Disallowing pat-mat from naming type arguments which are not top-level
dwijnand
Metadata
Metadata
Assignees
Labels
area:pattern-matchingitype: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)