Skip to content

Commit

Permalink
Use the upper bound of type skolems to enumerate subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Feb 1, 2021
1 parent 99a6820 commit 9cc5cf5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Expand Up @@ -164,6 +164,8 @@ trait TreeAndTypeAnalysis extends Debugging {
case sym if sym.isCase =>
List(List(tp))

case sym if sym.isTypeSkolem => enumerateSubtypes(sym.info.upperBound, grouped) // pos/t12277

case sym =>
debug.patmat("enum unsealed "+ ((tp, sym, sym.isSealed, isPrimitiveValueClass(sym))))
Nil
Expand Down
12 changes: 12 additions & 0 deletions test/files/pos/t12277.scala
@@ -0,0 +1,12 @@
// scalac: -Xlint:strict-unsealed-patmat -Werror
sealed trait A
final case class B() extends A
final case class C() extends A

object x extends App {

def matcher[A1 <: A](a1: A1) = a1 match {
case x @ (_: B | _: C) => println("B")
}

}
24 changes: 24 additions & 0 deletions test/files/run/patmat-behavior.check
Expand Up @@ -136,6 +136,30 @@ patmat-behavior.scala:55: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gc6[A](x: C[A]) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:57: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd1[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:58: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd2[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:59: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd3[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:60: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd4[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:61: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd5[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:62: warning: match may not be exhaustive.
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
def gd6[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x }
^
patmat-behavior.scala:68: warning: match may not be exhaustive.
It would fail on the following input: C00()
def gb1[A](x: C00[A]) = x match { case E00() => ??? ; case E10(x) => x ; case E20(x, y) => x ; case E01(xs @ _*) => xs.head ; case E11(x, ys @ _*) => x ; case E21(x, y, zs @ _*) => x }
Expand Down

0 comments on commit 9cc5cf5

Please sign in to comment.