Skip to content

Commit b94fb2f

Browse files
committed
Use the upper bound of type skolems to enumerate subtypes
1 parent 710de52 commit b94fb2f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ trait TreeAndTypeAnalysis extends Debugging {
8888
case sym if sym.isRefinementClass => enumerateRefinement(tp, grouped)
8989
case sym if sym.isSealed => enumerateSealed(tp, grouped)
9090
case sym if sym.isCase => List(List(tp))
91+
case sym if sym.isTypeSkolem => enumerateSubtypes(sym.info.upperBound, grouped) // pos/t12277
9192
case sym => debug.patmatResult(s"enum unsealed tp=$tp sym=$sym")(Nil)
9293
}
9394

test/files/pos/t12277.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// scalac: -Xlint:strict-unsealed-patmat -Werror
2+
sealed trait A
3+
final case class B() extends A
4+
final case class C() extends A
5+
6+
object x extends App {
7+
8+
def matcher[A1 <: A](a1: A1) = a1 match {
9+
case x @ (_: B | _: C) => println("B")
10+
}
11+
12+
}

test/files/run/patmat-behavior.check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ patmat-behavior.scala:55: warning: match may not be exhaustive.
136136
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
137137
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 }
138138
^
139+
patmat-behavior.scala:57: warning: match may not be exhaustive.
140+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
141+
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 }
142+
^
143+
patmat-behavior.scala:58: warning: match may not be exhaustive.
144+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
145+
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 }
146+
^
147+
patmat-behavior.scala:59: warning: match may not be exhaustive.
148+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
149+
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 }
150+
^
151+
patmat-behavior.scala:60: warning: match may not be exhaustive.
152+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
153+
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 }
154+
^
155+
patmat-behavior.scala:61: warning: match may not be exhaustive.
156+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
157+
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 }
158+
^
159+
patmat-behavior.scala:62: warning: match may not be exhaustive.
160+
It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _)
161+
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 }
162+
^
139163
patmat-behavior.scala:68: warning: match may not be exhaustive.
140164
It would fail on the following input: C00()
141165
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 }

0 commit comments

Comments
 (0)