File tree 7 files changed +31
-8
lines changed
compiler/src/dotty/tools/dotc/transform/patmat
7 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -841,8 +841,6 @@ object SpaceEngine {
841
841
if Nullables .unsafeNullsEnabled then self.stripNull() else self
842
842
843
843
private def exhaustivityCheckable (sel : Tree )(using Context ): Boolean = trace(i " exhaustivityCheckable( $sel ${sel.className}) " ) {
844
- val seen = collection.mutable.Set .empty[Symbol ]
845
-
846
844
// Possible to check everything, but be compatible with scalac by default
847
845
def isCheckable (tp : Type ): Boolean = trace(i " isCheckable( $tp ${tp.className}) " ):
848
846
val tpw = tp.widen.dealias.stripUnsafeNulls()
@@ -856,10 +854,7 @@ object SpaceEngine {
856
854
}) ||
857
855
tpw.isRef(defn.BooleanClass ) ||
858
856
classSym.isAllOf(JavaEnum ) ||
859
- classSym.is(Case ) && {
860
- if seen.add(classSym) then productSelectorTypes(tpw, sel.srcPos).exists(isCheckable(_))
861
- else true // recursive case class: return true and other members can still fail the check
862
- }
857
+ classSym.is(Case )
863
858
864
859
! sel.tpe.hasAnnotation(defn.UncheckedAnnot )
865
860
&& ! sel.tpe.hasAnnotation(defn.RuntimeCheckedAnnot )
Original file line number Diff line number Diff line change
1
+ sealed trait T_B
2
+ case class CC_A () extends T_B
3
+ case class CC_C () extends T_B
4
+
5
+ sealed trait T_A
6
+ case class CC_B [B ](a : B ,b: T_B ) extends T_A
7
+
8
+
9
+ @ main def test () = {
10
+ val v_a : CC_B [Int ] = null
11
+ val v_b : Int = v_a match {
12
+ case CC_B (12 , CC_A ()) => 0
13
+ case CC_B (_, CC_C ()) => 0
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ sealed trait T_A
2
+ case class CC_B [T ](a : T ) extends T_A
3
+
4
+ @ main def test () = {
5
+ val v_a : CC_B [Int ] = CC_B (10 )
6
+ val v_b : Int = v_a match {
7
+ case CC_B (12 ) => 0
8
+ }
9
+ }
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class Test {
42
42
case IntAnyVal (100 ) => 2
43
43
case IntAnyVal (1000 ) => 3
44
44
case IntAnyVal (10000 ) => 4
45
+ case _ => - 1
45
46
}
46
47
}
47
48
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ case class Composite[T](v: T)
5
5
def m (composite : Composite [? ]): Unit =
6
6
composite match {
7
7
case Composite [Int ](v) => println(v) // warn: cannot be checked at runtime
8
+ case _ => println(" OTHER" )
8
9
}
9
10
10
11
def m2 (composite : Composite [? ]): Unit =
Original file line number Diff line number Diff line change @@ -13,8 +13,10 @@ def Test[T] =
13
13
case _ : C => ??? // ok
14
14
C () match
15
15
case _ : O .T => ??? // warn
16
+ case _ => ???
16
17
C () match
17
18
case _ : T => ??? // warn
19
+ case _ => ???
18
20
19
21
(??? : Any ) match
20
22
case _ : List [O .T ] => ??? // warn
Original file line number Diff line number Diff line change 1
- //> using options -Xfatal-warnings - deprecation -feature
1
+ //> using options -deprecation -feature
2
2
3
3
abstract class Foo {
4
4
def bar (): Unit = this match {
@@ -7,7 +7,7 @@ abstract class Foo {
7
7
// Works fine
8
8
}
9
9
10
- def baz (that : Foo ): Unit = (this , that) match {
10
+ def baz (that : Foo ): Unit = (this , that) match { // warn: match may not be exhaustive.
11
11
case (Foo_1 (), _) => // do something
12
12
case (Foo_2 (), _) => // do something
13
13
// match may not be exhaustive
You can’t perform that action at this time.
0 commit comments