Skip to content

Commit d5f9047

Browse files
committed
Fix #8708: treat guard as false
1 parent 030249b commit d5f9047

File tree

6 files changed

+13
-3
lines changed

6 files changed

+13
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
812812
if (!exhaustivityCheckable(sel)) return
813813

814814
val patternSpace = cases.map({ x =>
815-
val space = project(x.pat)
815+
val space = if (x.guard.isEmpty) project(x.pat) else Empty
816816
debug.println(s"${x.pat.show} ====> ${show(space)}")
817817
space
818818
}).reduce((a, b) => Or(List(a, b)))

tests/patmat/i8708.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2: Pattern Match Exhaustivity: Some(_)

tests/patmat/i8708.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Main {
2+
def foo(x: Option[Int]): Int = x match {
3+
case Some(n) if n % 2 == 0 => n
4+
case None => 0
5+
}
6+
7+
def main(args: Array[String]): Unit = println(foo(Some(1)))
8+
}

tests/patmat/patmatexhaust.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
11: Pattern Match Exhaustivity: Bar(_)
33
23: Pattern Match Exhaustivity: (Qult(), Qult()), (Kult(_), Kult(_))
44
49: Pattern Match Exhaustivity: _: Gp
5+
53: Pattern Match Exhaustivity: _: Gp
56
59: Pattern Match Exhaustivity: Nil
67
75: Pattern Match Exhaustivity: _: B
78
87: Pattern Match Exhaustivity: _: C1

tests/patmat/t7631.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8: Pattern Match Exhaustivity: TestB()
1+
8: Pattern Match Exhaustivity: _: Test

tests/patmat/virtpatmat_apply.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2: Pattern Match Exhaustivity: List(_)
1+
2: Pattern Match Exhaustivity: List(_, _: _*)

0 commit comments

Comments
 (0)