From a4c540bbfd0ca9ebba9d24e2f43b2bb13d26104f Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 13 Dec 2021 18:15:57 +0000 Subject: [PATCH] Revert to fix false positive reachability warnings (cherry picked from commit 772c1bc2102c6e0461726b45387d3c0da0bbf0b2) --- .../dotty/tools/dotc/transform/patmat/Space.scala | 5 +++-- tests/neg-custom-args/fatal-warnings/i8711.check | 12 ++++++------ tests/patmat/i13485.check | 1 - tests/patmat/i13485.scala | 2 +- tests/patmat/i13931.scala | 4 ++++ 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 tests/patmat/i13931.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 2bfff0baad6e..a9ac4eaaa298 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -953,8 +953,9 @@ class SpaceEngine(using Context) extends SpaceLogic { if prev == Empty && covered == Empty then // defer until a case is reachable deferred ::= pat else { - for (pat <- deferred.reverseIterator) - report.warning(MatchCaseUnreachable(), pat.srcPos) + // FIXME: These should be emitted, but reverted for i13931 + //for (pat <- deferred.reverseIterator) + // report.warning(MatchCaseUnreachable(), pat.srcPos) if pat != EmptyTree // rethrow case of catch uses EmptyTree && isSubspace(covered, prev) then { diff --git a/tests/neg-custom-args/fatal-warnings/i8711.check b/tests/neg-custom-args/fatal-warnings/i8711.check index 0035af0755d4..0abda7a77ed6 100644 --- a/tests/neg-custom-args/fatal-warnings/i8711.check +++ b/tests/neg-custom-args/fatal-warnings/i8711.check @@ -1,8 +1,8 @@ --- [E030] Match case Unreachable Error: tests/neg-custom-args/fatal-warnings/i8711.scala:7:9 --------------------------- +-- Error: tests/neg-custom-args/fatal-warnings/i8711.scala:7:9 --------------------------------------------------------- 7 | case x: B => x // error: this case is unreachable since class A is not a subclass of class B - | ^^^^ - | Unreachable case --- [E030] Match case Unreachable Error: tests/neg-custom-args/fatal-warnings/i8711.scala:12:9 -------------------------- + | ^ + | this case is unreachable since type A and class B are unrelated +-- Error: tests/neg-custom-args/fatal-warnings/i8711.scala:12:9 -------------------------------------------------------- 12 | case x: C => x // error - | ^^^^ - | Unreachable case + | ^ + | this case is unreachable since type A | B and class C are unrelated diff --git a/tests/patmat/i13485.check b/tests/patmat/i13485.check index f9d066905a86..f05a4c6c0788 100644 --- a/tests/patmat/i13485.check +++ b/tests/patmat/i13485.check @@ -1,2 +1 @@ -11: Match case Unreachable 16: Match case Unreachable diff --git a/tests/patmat/i13485.scala b/tests/patmat/i13485.scala index 72cc3a3d2cd3..2c8ef5547704 100644 --- a/tests/patmat/i13485.scala +++ b/tests/patmat/i13485.scala @@ -8,7 +8,7 @@ sealed trait Foo class Bar def test1(bar: Bar) = bar match - case _: Foo => 1 + case _: Foo => 1 // FIXME: this is unreachable, but reverted for i13931 case _: Bar => 2 def test2(bar: Bar) = bar match diff --git a/tests/patmat/i13931.scala b/tests/patmat/i13931.scala new file mode 100644 index 000000000000..b6c8ba6accd8 --- /dev/null +++ b/tests/patmat/i13931.scala @@ -0,0 +1,4 @@ +class Test: + def test = Vector() match + case Seq() => println("empty") + case _ => println("non-empty")