Skip to content

Commit 36a8051

Browse files
authored
Merge pull request #106 from scala/backport-lts-3.3-21934
Backport "Fix scala#21914: Don't project nested wildcard patterns to nullable" to 3.3 LTS
2 parents 0eba599 + 6a68d2d commit 36a8051

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ object SpaceEngine {
690690
else NoType
691691
}.filter(_.exists)
692692
parts
693-
694693
case _ => ListOfNoType
695694
end rec
696695

tests/patmat/null.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
6: Pattern Match
22
13: Pattern Match
33
20: Pattern Match
4+
21: Match case Unreachable

tests/patmat/null.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ class Test {
1818
case Some(null) =>
1919
case None =>
2020
case y =>
21+
case _ =>
2122
}
2223
}

tests/warn/i20121.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sealed trait T_A[A, B]
2+
type X = T_A[Byte, Byte]
3+
4+
case class CC_B[A](a: A) extends T_A[A, X]
5+
6+
val v_a: T_A[X, X] = CC_B(null)
7+
val v_b = v_a match
8+
case CC_B(_) => 0 // warn: unreachable
9+
case _ => 1
10+
// for CC_B[A] to match T_A[X, X]
11+
// A := X
12+
// so require X, aka T_A[Byte, Byte]
13+
// which isn't instantiable, outside of null

tests/warn/i20122.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sealed trait T_B[C, D]
2+
3+
case class CC_A()
4+
case class CC_B[A, C](a: A) extends T_B[C, CC_A]
5+
case class CC_C[C, D](a: T_B[C, D]) extends T_B[Int, CC_A]
6+
case class CC_E(a: CC_C[Char, Byte])
7+
8+
val v_a: T_B[Int, CC_A] = CC_B(CC_E(CC_C(null)))
9+
val v_b = v_a match
10+
case CC_B(CC_E(CC_C(_))) => 0 // warn: unreachable
11+
case _ => 1
12+
// for CC_B[A, C] to match T_B[C, CC_A]
13+
// C <: Int, ok
14+
// A <: CC_E, ok
15+
// but you need a CC_C[Char, Byte]
16+
// which requires a T_B[Char, Byte]
17+
// which isn't instantiable, outside of null

tests/warn/i20123.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sealed trait T_A[A, B]
2+
sealed trait T_B[C]
3+
4+
case class CC_D[A, C]() extends T_A[A, C]
5+
case class CC_E() extends T_B[Nothing]
6+
case class CC_G[A, C](c: C) extends T_A[A, C]
7+
8+
val v_a: T_A[Boolean, T_B[Boolean]] = CC_G(null)
9+
val v_b = v_a match {
10+
case CC_D() => 0
11+
case CC_G(_) => 1 // warn: unreachable
12+
// for CC_G[A, C] to match T_A[Boolean, T_B[Boolean]]
13+
// A := Boolean, which is ok
14+
// C := T_B[Boolean],
15+
// which isn't instantiable, outside of null
16+
}

0 commit comments

Comments
 (0)