diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 65fafd092269..649f2a8f8db0 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -768,4 +768,23 @@ object messages { | - null |""" } + + case class PatternMatchExhaustivity(uncovered: String)(implicit ctx: Context) + extends Message(29) { + val kind = "Pattern Match Exhaustivity" + val msg = + hl"""|match may not be exhaustive. + | + |It would fail on: $uncovered""" + + + val explanation = "" + } + + case class MatchCaseUnreachable()(implicit ctx: Context) + extends Message(30) { + val kind = s"""Match ${hl"case"} Unreachable""" + val msg = "unreachable code" + val explanation = "" + } } diff --git a/src/dotty/tools/dotc/transform/patmat/Space.scala b/src/dotty/tools/dotc/transform/patmat/Space.scala index 830d0f938b9b..8d926fcf024c 100644 --- a/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -12,6 +12,7 @@ import core.Symbols._ import core.StdNames._ import core.NameOps._ import core.Constants._ +import reporting.diagnostic.messages._ /** Space logic for checking exhaustivity and unreachability of pattern matching * @@ -586,13 +587,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { val patternSpace = cases.map(x => project(x.pat)).reduce((a, b) => Or(List(a, b))) val uncovered = simplify(minus(Typ(selTyp, true), patternSpace)) - if (uncovered != Empty) { - ctx.warning( - "match may not be exhaustive.\n" + - s"It would fail on the following input: " + - show(uncovered), _match.pos - ) - } + if (uncovered != Empty) + ctx.warning(PatternMatchExhaustivity(show(uncovered)), _match.pos) } def checkRedundancy(_match: Match): Unit = { @@ -612,7 +608,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { val curr = project(cases(i).pat) if (isSubspace(curr, prevs)) { - ctx.warning("unreachable code", cases(i).body.pos) + ctx.warning(MatchCaseUnreachable(), cases(i).body.pos) } } } diff --git a/test/dotty/tools/dotc/reporting/TestReporter.scala b/test/dotty/tools/dotc/reporting/TestReporter.scala new file mode 100644 index 000000000000..70d18d03135c --- /dev/null +++ b/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -0,0 +1,52 @@ +package dotty.tools +package dotc +package reporting + +import scala.collection.mutable +import util.SourcePosition +import core.Contexts._ +import Reporter._ +import java.io.PrintWriter +import scala.reflect.internal.util._ +import diagnostic.{ Message, MessageContainer, NoExplanation } +import diagnostic.messages._ + +class TestReporter(writer: PrintWriter) extends Reporter +with UniqueMessagePositions with HideNonSensicalMessages { + + import MessageContainer._ + + /** maximal number of error messages to be printed */ + protected def ErrorLimit = 100 + + def printPos(pos: SourcePosition): Unit = + if (pos.exists) { + if (pos.outer.exists) { + writer.println(s"\ninlined at ${pos.outer}:\n") + printPos(pos.outer) + } + } + + /** Prints the message with the given position indication. */ + def printMessageAndPos(msg: String, pos: SourcePosition)(implicit ctx: Context): Unit = { + val posStr = s"${pos.line + 1}: " + writer.println(posStr + msg) + printPos(pos) + } + + override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = { + // Here we add extra information that we should know about the error message + val extra = m.contained match { + case pm: PatternMatchExhaustivity => s": ${pm.uncovered}" + case _ => "" + } + + m match { + case m: Error => + printMessageAndPos(m.contained.kind + extra, m.pos) + case w: Warning => + printMessageAndPos(w.contained.kind + extra, w.pos) + case _ => + } + } +} diff --git a/test/test/transform/PatmatExhaustivityTest.scala b/test/test/transform/PatmatExhaustivityTest.scala new file mode 100644 index 000000000000..c77ba501f867 --- /dev/null +++ b/test/test/transform/PatmatExhaustivityTest.scala @@ -0,0 +1,90 @@ +package test.transform + +import java.io._ + +import scala.io.Source._ +import scala.reflect.io.Directory +import org.junit.Test +import dotty.tools.dotc.Main +import dotty.tools.dotc.reporting.TestReporter + +class PatmatExhaustivityTest { + val testsDir = "./tests/patmat" + // stop-after: patmatexhaust-huge.scala crash compiler + val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat") + + private def compileFile(file: File) = { + val stringBuffer = new StringWriter() + val reporter = new TestReporter(new PrintWriter(stringBuffer)) + + try { + Main.process((file.getPath::options).toArray, reporter, null) + } catch { + case e: Throwable => + println(s"Compile $file exception:") + e.printStackTrace() + } + + val actual = stringBuffer.toString.trim + val checkFilePath = file.getAbsolutePath.stripSuffix(".scala") + ".check" + val checkContent = + if (new File(checkFilePath).exists) + fromFile(checkFilePath).getLines.mkString("\n").trim + else "" + + (file, checkContent, actual) + } + + /** A single test with multiple files grouped in a folder */ + private def compileDir(file: File) = { + val stringBuffer = new StringWriter() + val reporter = new TestReporter(new PrintWriter(stringBuffer)) + + val files = Directory(file.getPath).list.toList + .filter(f => f.extension == "scala" || f.extension == "java" ) + .map(_.jfile.getPath) + + try { + Main.process((options ++ files).toArray, reporter, null) + } catch { + case e: Throwable => + println(s"Compile $file exception:") + e.printStackTrace() + } + + val actual = stringBuffer.toString.trim + val checkFilePath = file.getPath + File.separator + "expected.check" + val checkContent = + if (new File(checkFilePath).exists) + fromFile(checkFilePath).getLines.mkString("\n").trim + else "" + + (file, checkContent, actual) + } + + @Test def patmatExhaustivity: Unit = { + val res = Directory(testsDir).list.toList + .filter(f => f.extension == "scala" || f.isDirectory) + .map { f => + if (f.isDirectory) + compileDir(f.jfile) + else + compileFile(f.jfile) + } + + val failed = res.filter { case (_, expected, actual) => expected != actual } + val ignored = Directory(testsDir).list.toList.filter(_.extension == "ignore") + + failed.foreach { case (file, expected, actual) => + println(s"\n----------------- incorrect output for $file --------------\n" + + s"Expected:\n---------\n$expected\n\nActual:\n-------\n$actual\n" + ) + } + + val msg = s"Total: ${res.length + ignored.length}, Failed: ${failed.length}, Ignored: ${ignored.length}" + + assert(failed.length == 0, msg) + + println(msg) + } +} diff --git a/tests/patmat/NonAbstractSealed.check b/tests/patmat/NonAbstractSealed.check index 9224ee370ce0..5ce80f81b02f 100644 --- a/tests/patmat/NonAbstractSealed.check +++ b/tests/patmat/NonAbstractSealed.check @@ -1,5 +1 @@ -./tests/patmat/NonAbstractSealed.scala:6: warning: match may not be exhaustive. -It would fail on the following input: _: A - (null: A) match { - ^ -one warning found \ No newline at end of file +6: Pattern Match Exhaustivity: _: A diff --git a/tests/patmat/enum/expected.check b/tests/patmat/enum/expected.check index b3dafa8bdd02..296cf8bb2a75 100644 --- a/tests/patmat/enum/expected.check +++ b/tests/patmat/enum/expected.check @@ -1,9 +1,2 @@ -./tests/patmat/enum/patmat-enum.scala:4: warning: match may not be exhaustive. -It would fail on the following input: SATURDAY, FRIDAY, THURSDAY, SUNDAY - day match { - ^ -./tests/patmat/enum/patmat-enum.scala:15: warning: match may not be exhaustive. -It would fail on the following input: SATURDAY, FRIDAY, THURSDAY - day match { - ^ -two warnings found \ No newline at end of file +4: Pattern Match Exhaustivity: SATURDAY, FRIDAY, THURSDAY, SUNDAY +15: Pattern Match Exhaustivity: SATURDAY, FRIDAY, THURSDAY diff --git a/tests/patmat/exhausting.check b/tests/patmat/exhausting.check index 790b12334f0b..b8d1d8408f4d 100644 --- a/tests/patmat/exhausting.check +++ b/tests/patmat/exhausting.check @@ -1,25 +1,6 @@ -./tests/patmat/exhausting.scala:21: warning: match may not be exhaustive. -It would fail on the following input: List(_), List(_, _, _) - def fail1[T](xs: List[T]) = xs match { - ^ -./tests/patmat/exhausting.scala:27: warning: match may not be exhaustive. -It would fail on the following input: Nil - def fail2[T](xs: List[T]) = xs match { - ^ -./tests/patmat/exhausting.scala:32: warning: match may not be exhaustive. -It would fail on the following input: List(_, _) - def fail3a(xs: List[Int]) = xs match { - ^ -./tests/patmat/exhausting.scala:39: warning: match may not be exhaustive. -It would fail on the following input: Bar3 - def fail3[T](x: Foo[T]) = x match { - ^ -./tests/patmat/exhausting.scala:44: warning: match may not be exhaustive. -It would fail on the following input: (Bar2, Bar2) - def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { - ^ -./tests/patmat/exhausting.scala:53: warning: match may not be exhaustive. -It would fail on the following input: (Bar2, Bar2), (Bar2, Bar1), (Bar1, Bar3), (Bar1, Bar2) - def fail5[T](xx: (Foo[T], Foo[T])) = xx match { - ^ -6 warnings found +21: Pattern Match Exhaustivity: List(_), List(_, _, _) +27: Pattern Match Exhaustivity: Nil +32: Pattern Match Exhaustivity: List(_, _) +39: Pattern Match Exhaustivity: Bar3 +44: Pattern Match Exhaustivity: (Bar2, Bar2) +53: Pattern Match Exhaustivity: (Bar2, Bar2), (Bar2, Bar1), (Bar1, Bar3), (Bar1, Bar2) diff --git a/tests/patmat/gadt.check b/tests/patmat/gadt.check index f2154fa601f9..71860e52a9e3 100644 --- a/tests/patmat/gadt.check +++ b/tests/patmat/gadt.check @@ -1,17 +1,4 @@ -./tests/patmat/gadt.scala:13: warning: match may not be exhaustive. -It would fail on the following input: IntLit(_) - def foo1b(x: Expr[Int]) = x match { - ^ -./tests/patmat/gadt.scala:22: warning: match may not be exhaustive. -It would fail on the following input: Or(_, _) - def foo2b(x: Expr[Boolean]) = x match { - ^ -./tests/patmat/gadt.scala:45: warning: match may not be exhaustive. -It would fail on the following input: BooleanLit(_), IntLit(_) - def foo4b(x: Expr[_]) = x match { - ^ -./tests/patmat/gadt.scala:55: warning: match may not be exhaustive. -It would fail on the following input: Sum(_, _) - def foo5b[T <: Int](x: Expr[T]) = x match { - ^ -four warnings found \ No newline at end of file +13: Pattern Match Exhaustivity: IntLit(_) +22: Pattern Match Exhaustivity: Or(_, _) +45: Pattern Match Exhaustivity: BooleanLit(_), IntLit(_) +55: Pattern Match Exhaustivity: Sum(_, _) diff --git a/tests/patmat/i947.check b/tests/patmat/i947.check index 5cce559c4834..024161675702 100644 --- a/tests/patmat/i947.check +++ b/tests/patmat/i947.check @@ -1,4 +1 @@ -./tests/patmat/i947.scala:10: warning: unreachable code - case ys: List[d18383] => false - ^ -one warning found \ No newline at end of file +10: Match case Unreachable diff --git a/tests/patmat/patmat-adt.check b/tests/patmat/patmat-adt.check index f4e1ce369e50..4adcdc49cd2f 100644 --- a/tests/patmat/patmat-adt.check +++ b/tests/patmat/patmat-adt.check @@ -1,21 +1,5 @@ -./tests/patmat/patmat-adt.scala:7: warning: match may not be exhaustive. -It would fail on the following input: Bad(Good(_)), Good(Bad(_)) - def foo1a(x: Odd) = x match { // warning: Good(_: Bad), Bad(_: Good) - ^ -./tests/patmat/patmat-adt.scala:19: warning: match may not be exhaustive. -It would fail on the following input: Some(_) - def foo2(x: Option[Int]) = x match { // warning: Some(_: Int) - ^ -./tests/patmat/patmat-adt.scala:24: warning: match may not be exhaustive. -It would fail on the following input: (None, Some(_)), (_, Some(_)) - def foo3a[T](x: Option[T]) = (x, x) match { // warning: (Some(_), Some(_)), (None, Some(_)) - ^ -./tests/patmat/patmat-adt.scala:29: warning: match may not be exhaustive. -It would fail on the following input: (None, None), (Some(_), Some(_)) - def foo3b[T](x: Option[T]) = (x, x) match { // warning: (Some(_), Some(_)), (None, None) - ^ -./tests/patmat/patmat-adt.scala:50: warning: match may not be exhaustive. -It would fail on the following input: LetL(BooleanLit), LetL(IntLit) - def foo5(tree: Tree) : Any = tree match { - ^ -5 warnings found \ No newline at end of file +7: Pattern Match Exhaustivity: Bad(Good(_)), Good(Bad(_)) +19: Pattern Match Exhaustivity: Some(_) +24: Pattern Match Exhaustivity: (None, Some(_)), (_, Some(_)) +29: Pattern Match Exhaustivity: (None, None), (Some(_), Some(_)) +50: Pattern Match Exhaustivity: LetL(BooleanLit), LetL(IntLit) diff --git a/tests/patmat/patmat-indent.check b/tests/patmat/patmat-indent.check index 3a76e0a9581b..79845ebcfd17 100644 --- a/tests/patmat/patmat-indent.check +++ b/tests/patmat/patmat-indent.check @@ -1,13 +1,3 @@ -./tests/patmat/patmat-indent.scala:9: warning: match may not be exhaustive. -It would fail on the following input: Nil - def foo1a[T](l: List[T]) = l match { - ^ -./tests/patmat/patmat-indent.scala:23: warning: match may not be exhaustive. -It would fail on the following input: _: Boolean - def foo2(b: Boolean) = b match { - ^ -./tests/patmat/patmat-indent.scala:27: warning: match may not be exhaustive. -It would fail on the following input: _: Int - def foo3(x: Int) = x match { - ^ -three warnings found \ No newline at end of file +9: Pattern Match Exhaustivity: Nil +23: Pattern Match Exhaustivity: _: Boolean +27: Pattern Match Exhaustivity: _: Int diff --git a/tests/patmat/patmat-ortype.check b/tests/patmat/patmat-ortype.check index 2291da251994..0bd790437769 100644 --- a/tests/patmat/patmat-ortype.check +++ b/tests/patmat/patmat-ortype.check @@ -1,13 +1,3 @@ -./tests/patmat/patmat-ortype.scala:8: warning: match may not be exhaustive. -It would fail on the following input: _: String - def foo2a(x: Int | Double | String) = x match { // _: String not matched - ^ -./tests/patmat/patmat-ortype.scala:18: warning: match may not be exhaustive. -It would fail on the following input: Some(_: String), None - def foo3(x: Option[Int | Double | String]) = x match { // warning: None, Some(_: String) not matched - ^ -./tests/patmat/patmat-ortype.scala:36: warning: match may not be exhaustive. -It would fail on the following input: Some(_: String) - def foo5b(x: Option[Int | Double | String]) = x match { // warning: Some(_: String) not matched - ^ -three warnings found \ No newline at end of file +8: Pattern Match Exhaustivity: _: String +18: Pattern Match Exhaustivity: Some(_: String), None +36: Pattern Match Exhaustivity: Some(_: String) diff --git a/tests/patmat/patmatexhaust-huge.check b/tests/patmat/patmatexhaust-huge.check index 06cac90bd5e7..f622622decf3 100644 --- a/tests/patmat/patmatexhaust-huge.check +++ b/tests/patmat/patmatexhaust-huge.check @@ -1,5 +1 @@ -./tests/patmat/patmatexhaust-huge.scala:404: warning: match may not be exhaustive. -It would fail on the following input: C397, C392 - def f(c: C): Int = c match { - ^ -one warning found \ No newline at end of file +404: Pattern Match Exhaustivity: C397, C392 diff --git a/tests/patmat/patmatexhaust.check b/tests/patmat/patmatexhaust.check index ef2b578d6e3b..3de93cfdbbd4 100644 --- a/tests/patmat/patmatexhaust.check +++ b/tests/patmat/patmatexhaust.check @@ -1,33 +1,8 @@ -./tests/patmat/patmatexhaust.scala:7: warning: match may not be exhaustive. -It would fail on the following input: Baz - def ma1(x:Foo) = x match { - ^ -./tests/patmat/patmatexhaust.scala:11: warning: match may not be exhaustive. -It would fail on the following input: Bar(_) - def ma2(x:Foo) = x match { - ^ -./tests/patmat/patmatexhaust.scala:23: warning: match may not be exhaustive. -It would fail on the following input: (Qult(), Qult()), (Kult(_), Kult(_)) - def ma3(x:Mult) = (x,x) match { // not exhaustive - ^ -./tests/patmat/patmatexhaust.scala:49: warning: match may not be exhaustive. -It would fail on the following input: _: Gp - def ma4(x:Deep) = x match { // missing cases: Gu, Gp which is not abstract so must be included - ^ -./tests/patmat/patmatexhaust.scala:75: warning: match may not be exhaustive. -It would fail on the following input: _: B - def ma9(x: B) = x match { - ^ -./tests/patmat/patmatexhaust.scala:100: warning: match may not be exhaustive. -It would fail on the following input: _: C1 - def ma10(x: C) = x match { // not exhaustive: C1 is not sealed. - ^ -./tests/patmat/patmatexhaust.scala:114: warning: match may not be exhaustive. -It would fail on the following input: D2(), D1 - def ma10(x: C) = x match { // not exhaustive: C1 has subclasses. - ^ -./tests/patmat/patmatexhaust.scala:126: warning: match may not be exhaustive. -It would fail on the following input: _: C1 - def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. - ^ -8 warnings found \ No newline at end of file +7: Pattern Match Exhaustivity: Baz +11: Pattern Match Exhaustivity: Bar(_) +23: Pattern Match Exhaustivity: (Qult(), Qult()), (Kult(_), Kult(_)) +49: Pattern Match Exhaustivity: _: Gp +75: Pattern Match Exhaustivity: _: B +100: Pattern Match Exhaustivity: _: C1 +114: Pattern Match Exhaustivity: D2(), D1 +126: Pattern Match Exhaustivity: _: C1 diff --git a/tests/patmat/sealed-java-enums.check b/tests/patmat/sealed-java-enums.check index ed93d3d400d6..86e73f0da35e 100644 --- a/tests/patmat/sealed-java-enums.check +++ b/tests/patmat/sealed-java-enums.check @@ -1,5 +1 @@ -./tests/patmat/sealed-java-enums.scala:5: warning: match may not be exhaustive. -It would fail on the following input: TERMINATED, TIMED_WAITING, BLOCKED - def f(state: State) = state match { - ^ -one warning found +5: Pattern Match Exhaustivity: TERMINATED, TIMED_WAITING, BLOCKED diff --git a/tests/patmat/t2442/expected.check b/tests/patmat/t2442/expected.check index 33110ce43343..7bbcb4c2d8fa 100644 --- a/tests/patmat/t2442/expected.check +++ b/tests/patmat/t2442/expected.check @@ -1,9 +1,2 @@ -./tests/patmat/t2442/t2442.scala:4: warning: match may not be exhaustive. -It would fail on the following input: THREE - def f(e: MyEnum) = e match { - ^ -./tests/patmat/t2442/t2442.scala:11: warning: match may not be exhaustive. -It would fail on the following input: BLUE - def g(e: MySecondEnum) = e match { - ^ -two warnings found +4: Pattern Match Exhaustivity: THREE +11: Pattern Match Exhaustivity: BLUE diff --git a/tests/patmat/t3098/expected.check b/tests/patmat/t3098/expected.check index 33190411102c..3198aa2ef672 100644 --- a/tests/patmat/t3098/expected.check +++ b/tests/patmat/t3098/expected.check @@ -1,5 +1 @@ -./tests/patmat/t3098/b.scala:3: warning: match may not be exhaustive. -It would fail on the following input: _: C - def f = (null: T) match { - ^ -one warning found \ No newline at end of file +3: Pattern Match Exhaustivity: _: C diff --git a/tests/patmat/t3111.check b/tests/patmat/t3111.check index 46ff0a6a9376..be1e7d8084f1 100644 --- a/tests/patmat/t3111.check +++ b/tests/patmat/t3111.check @@ -1,8 +1,2 @@ -./tests/patmat/t3111.scala:4: warning: match may not be exhaustive. -It would fail on the following input: false - bool match { - ^ -./tests/patmat/t3111.scala:11: warning: unreachable code - case _ => "cats and dogs living together... mass hysteria!" - ^ -two warnings found \ No newline at end of file +4: Pattern Match Exhaustivity: false +11: Match case Unreachable diff --git a/tests/patmat/t3163.check b/tests/patmat/t3163.check index 3da94e2c2a40..51c58f9e3fe8 100644 --- a/tests/patmat/t3163.check +++ b/tests/patmat/t3163.check @@ -1,5 +1 @@ -./tests/patmat/t3163.scala:2: warning: match may not be exhaustive. -It would fail on the following input: _: AnyVal - def foo(x : AnyVal) = x match {case b : Boolean => "It's a bool"} - ^ -one warning found \ No newline at end of file +2: Pattern Match Exhaustivity: _: AnyVal diff --git a/tests/patmat/t3683a.check b/tests/patmat/t3683a.check index df5e691c64c9..fdcafc5961b9 100644 --- a/tests/patmat/t3683a.check +++ b/tests/patmat/t3683a.check @@ -1,5 +1 @@ -./tests/patmat/t3683a.scala:14: warning: match may not be exhaustive. -It would fail on the following input: XX() - w match { - ^ -one warning found +14: Pattern Match Exhaustivity: XX() diff --git a/tests/patmat/t4408.check b/tests/patmat/t4408.check index 53bfe1c2c564..2bd8b583f551 100644 --- a/tests/patmat/t4408.check +++ b/tests/patmat/t4408.check @@ -1,5 +1 @@ -./tests/patmat/t4408.scala:2: warning: match may not be exhaustive. -It would fail on the following input: List(_, _, _) - def printList(in: List[String]): Unit = in match { - ^ -one warning found \ No newline at end of file +2: Pattern Match Exhaustivity: List(_, _, _) diff --git a/tests/patmat/t4526.check b/tests/patmat/t4526.check index b577cbc0c121..802d0fe22d54 100644 --- a/tests/patmat/t4526.check +++ b/tests/patmat/t4526.check @@ -1,13 +1,3 @@ -./tests/patmat/t4526.scala:2: warning: match may not be exhaustive. -It would fail on the following input: _: Int - def foo(a: Int) = a match { - ^ -./tests/patmat/t4526.scala:7: warning: match may not be exhaustive. -It would fail on the following input: (_, _) - def bar(a: (Int, Int)) = a match { - ^ -./tests/patmat/t4526.scala:12: warning: match may not be exhaustive. -It would fail on the following input: (false, false), (true, true) - def baz(a: (Boolean, Boolean)) = a match { - ^ -three warnings found \ No newline at end of file +2: Pattern Match Exhaustivity: _: Int +7: Pattern Match Exhaustivity: (_, _) +12: Pattern Match Exhaustivity: (false, false), (true, true) diff --git a/tests/patmat/t4691.check b/tests/patmat/t4691.check index 4d2c24506810..5fbcb267ab80 100644 --- a/tests/patmat/t4691.check +++ b/tests/patmat/t4691.check @@ -1,5 +1 @@ -./tests/patmat/t4691.scala:15: warning: match may not be exhaustive. -It would fail on the following input: NodeType2(_) - def test (x: Node) = x match { - ^ -one warning found \ No newline at end of file +15: Pattern Match Exhaustivity: NodeType2(_) diff --git a/tests/patmat/t4691_exhaust_extractor.check b/tests/patmat/t4691_exhaust_extractor.check index e7d1e17f9e7d..3122f85c85e3 100644 --- a/tests/patmat/t4691_exhaust_extractor.check +++ b/tests/patmat/t4691_exhaust_extractor.check @@ -1,13 +1,3 @@ -./tests/patmat/t4691_exhaust_extractor.scala:17: warning: match may not be exhaustive. -It would fail on the following input: _: Bar3 - def f1(x: Foo) = x match { - ^ -./tests/patmat/t4691_exhaust_extractor.scala:23: warning: match may not be exhaustive. -It would fail on the following input: _: Bar3 - def f2(x: Foo) = x match { - ^ -./tests/patmat/t4691_exhaust_extractor.scala:29: warning: match may not be exhaustive. -It would fail on the following input: _: Bar3 - def f3(x: Foo) = x match { - ^ -three warnings found +17: Pattern Match Exhaustivity: _: Bar3 +23: Pattern Match Exhaustivity: _: Bar3 +29: Pattern Match Exhaustivity: _: Bar3 diff --git a/tests/patmat/t5440.check b/tests/patmat/t5440.check index 0780d652945e..511fcc6b44f0 100644 --- a/tests/patmat/t5440.check +++ b/tests/patmat/t5440.check @@ -1,5 +1 @@ -./tests/patmat/t5440.scala:2: warning: match may not be exhaustive. -It would fail on the following input: (Nil, List(_)), (List(_), Nil) - def merge(list1: List[Long], list2: List[Long]): Boolean = (list1, list2) match { - ^ -one warning found +2: Pattern Match Exhaustivity: (Nil, List(_)), (List(_), Nil) diff --git a/tests/patmat/t6420.check b/tests/patmat/t6420.check index c62b33d181a5..73acf14544fe 100644 --- a/tests/patmat/t6420.check +++ b/tests/patmat/t6420.check @@ -1,5 +1 @@ -./tests/patmat/t6420.scala:5: warning: match may not be exhaustive. -It would fail on the following input: (Nil, _), (List(_, _), _), (Nil, Nil), (Nil, List(_, _)), (List(_, _), Nil), (List(_, _), List(_, _)), (_, Nil), (_, List(_, _)) - def foo(x: List[Boolean], y: List[Boolean]) = (x,y) match { - ^ -one warning found \ No newline at end of file +5: Pattern Match Exhaustivity: (Nil, _), (List(_, _), _), (Nil, Nil), (Nil, List(_, _)), (List(_, _), Nil), (List(_, _), List(_, _)), (_, Nil), (_, List(_, _)) diff --git a/tests/patmat/t6582_exhaust_big.check b/tests/patmat/t6582_exhaust_big.check index c244e5ba5732..3721edc7021d 100644 --- a/tests/patmat/t6582_exhaust_big.check +++ b/tests/patmat/t6582_exhaust_big.check @@ -1,5 +1 @@ -./tests/patmat/t6582_exhaust_big.scala:27: warning: match may not be exhaustive. -It would fail on the following input: Z.Z11() - def foo(z: Z) = z match { - ^ -one warning found +27: Pattern Match Exhaustivity: Z.Z11() diff --git a/tests/patmat/t7020.check b/tests/patmat/t7020.check index c091535ae3fd..a44384946184 100644 --- a/tests/patmat/t7020.check +++ b/tests/patmat/t7020.check @@ -1,17 +1,4 @@ -./tests/patmat/t7020.scala:3: warning: match may not be exhaustive. -It would fail on the following input: List(_, _) - List(5) match { - ^ -./tests/patmat/t7020.scala:10: warning: match may not be exhaustive. -It would fail on the following input: List(_, _) - List(5) match { - ^ -./tests/patmat/t7020.scala:17: warning: match may not be exhaustive. -It would fail on the following input: List(_, _) - List(5) match { - ^ -./tests/patmat/t7020.scala:24: warning: match may not be exhaustive. -It would fail on the following input: List(_, _) - List(5) match { - ^ -four warnings found +3: Pattern Match Exhaustivity: List(_, _) +10: Pattern Match Exhaustivity: List(_, _) +17: Pattern Match Exhaustivity: List(_, _) +24: Pattern Match Exhaustivity: List(_, _) diff --git a/tests/patmat/t7285.check b/tests/patmat/t7285.check index 703706cdc532..1c2841920935 100644 --- a/tests/patmat/t7285.check +++ b/tests/patmat/t7285.check @@ -1,13 +1,3 @@ -./tests/patmat/t7285.scala:15: warning: match may not be exhaustive. -It would fail on the following input: (Up, Down) - (d1, d2) match { - ^ -./tests/patmat/t7285.scala:33: warning: match may not be exhaustive. -It would fail on the following input: Down - (d1) match { - ^ -./tests/patmat/t7285.scala:51: warning: match may not be exhaustive. -It would fail on the following input: (Base.Up, Base.Down) - (d1, d2) match { - ^ -three warnings found \ No newline at end of file +15: Pattern Match Exhaustivity: (Up, Down) +33: Pattern Match Exhaustivity: Down +51: Pattern Match Exhaustivity: (Base.Up, Base.Down) diff --git a/tests/patmat/t7466.check b/tests/patmat/t7466.check index 8e575f6a213f..35227484e184 100644 --- a/tests/patmat/t7466.check +++ b/tests/patmat/t7466.check @@ -1,5 +1 @@ -./tests/patmat/t7466.scala:8: warning: match may not be exhaustive. -It would fail on the following input: (_, _) - (b1, b2) match { - ^ -one warning found \ No newline at end of file +8: Pattern Match Exhaustivity: (_, _) diff --git a/tests/patmat/t7631.check b/tests/patmat/t7631.check index ede3703e2a60..78dc1ac36c19 100644 --- a/tests/patmat/t7631.check +++ b/tests/patmat/t7631.check @@ -1,5 +1 @@ -./tests/patmat/t7631.scala:8: warning: match may not be exhaustive. -It would fail on the following input: TestB() - val x = input match { - ^ -one warning found \ No newline at end of file +8: Pattern Match Exhaustivity: TestB() diff --git a/tests/patmat/t7669.check b/tests/patmat/t7669.check index 2804dbf5c3ac..a8a331424eb6 100644 --- a/tests/patmat/t7669.check +++ b/tests/patmat/t7669.check @@ -1,5 +1 @@ -./tests/patmat/t7669.scala:10: warning: match may not be exhaustive. -It would fail on the following input: NotHandled(_) - def exhausto(expr: Expr): Unit = expr match { - ^ -one warning found \ No newline at end of file +10: Pattern Match Exhaustivity: NotHandled(_) diff --git a/tests/patmat/t7746.check b/tests/patmat/t7746.check index be4c53570c68..cdba0449f0ab 100644 --- a/tests/patmat/t7746.check +++ b/tests/patmat/t7746.check @@ -1,5 +1 @@ -./tests/patmat/t7746.scala:2: warning: match may not be exhaustive. -It would fail on the following input: Some(_), None - def f[T](x: Option[T]) = x match { - ^ -one warning found \ No newline at end of file +2: Pattern Match Exhaustivity: Some(_), None diff --git a/tests/patmat/t8178.check b/tests/patmat/t8178.check index 963845f5310c..1bcae1c1fd15 100644 --- a/tests/patmat/t8178.check +++ b/tests/patmat/t8178.check @@ -1,13 +1,3 @@ -./tests/patmat/t8178.scala:6: warning: match may not be exhaustive. -It would fail on the following input: FailsChild2(_) - f match { - ^ -./tests/patmat/t8178.scala:14: warning: match may not be exhaustive. -It would fail on the following input: VarArgs1(_) - f match { - ^ -./tests/patmat/t8178.scala:27: warning: match may not be exhaustive. -It would fail on the following input: SeqArgs2(_) - f match { - ^ -three warnings found \ No newline at end of file +6: Pattern Match Exhaustivity: FailsChild2(_) +14: Pattern Match Exhaustivity: VarArgs1(_) +27: Pattern Match Exhaustivity: SeqArgs2(_) diff --git a/tests/patmat/t8412.check b/tests/patmat/t8412.check index b82b33999613..08ee2636dd46 100644 --- a/tests/patmat/t8412.check +++ b/tests/patmat/t8412.check @@ -1,5 +1 @@ -./tests/patmat/t8412.scala:7: warning: match may not be exhaustive. -It would fail on the following input: Lit(_) - tree match { - ^ -one warning found \ No newline at end of file +7: Pattern Match Exhaustivity: Lit(_) diff --git a/tests/patmat/t8430.check b/tests/patmat/t8430.check index 4493062bfceb..d72de523733e 100644 --- a/tests/patmat/t8430.check +++ b/tests/patmat/t8430.check @@ -1,5 +1 @@ -./tests/patmat/t8430.scala:15: warning: match may not be exhaustive. -It would fail on the following input: LetF, LetC, LetP, LetL(UnitLit), LetL(BooleanLit), LetL(IntLit) - def transform(tree: Tree) : Any = tree match { - ^ -one warning found \ No newline at end of file +15: Pattern Match Exhaustivity: LetF, LetC, LetP, LetL(UnitLit), LetL(BooleanLit), LetL(IntLit) diff --git a/tests/patmat/t8511.check b/tests/patmat/t8511.check index df07d019aa33..6f63f1040f5b 100644 --- a/tests/patmat/t8511.check +++ b/tests/patmat/t8511.check @@ -1,5 +1 @@ -./tests/patmat/t8511.scala:18: warning: match may not be exhaustive. -It would fail on the following input: Baz(), Bar(_) - private def logic(head: Expr): String = head match { - ^ -one warning found \ No newline at end of file +18: Pattern Match Exhaustivity: Baz(), Bar(_) diff --git a/tests/patmat/t8700a/expected.check b/tests/patmat/t8700a/expected.check index 83f1c5a9ea6c..c4774f8241b0 100644 --- a/tests/patmat/t8700a/expected.check +++ b/tests/patmat/t8700a/expected.check @@ -1,9 +1,2 @@ -./tests/patmat/t8700a/Bar.scala:2: warning: match may not be exhaustive. -It would fail on the following input: B - def bar1(foo: Foo) = foo match { - ^ -./tests/patmat/t8700a/Bar.scala:6: warning: match may not be exhaustive. -It would fail on the following input: B - def bar2(foo: Baz) = foo match { - ^ -two warnings found +2: Pattern Match Exhaustivity: B +6: Pattern Match Exhaustivity: B diff --git a/tests/patmat/t9129.check b/tests/patmat/t9129.check index aa722a61acad..3236bb049a5b 100644 --- a/tests/patmat/t9129.check +++ b/tests/patmat/t9129.check @@ -1,5 +1 @@ -./tests/patmat/t9129.scala:21: warning: match may not be exhaustive. -It would fail on the following input: Two(B2, A2), Two(_, A2) - def foo(c: C): Unit = c match { - ^ -one warning found \ No newline at end of file +21: Pattern Match Exhaustivity: Two(B2, A2), Two(_, A2) diff --git a/tests/patmat/t9232.check b/tests/patmat/t9232.check index c3957c0ffa1d..36949147a2e7 100644 --- a/tests/patmat/t9232.check +++ b/tests/patmat/t9232.check @@ -1,5 +1 @@ -./tests/patmat/t9232.scala:13: warning: match may not be exhaustive. -It would fail on the following input: Node2() - def transformTree(tree: Tree): Any = tree match { - ^ -one warning found +13: Pattern Match Exhaustivity: Node2() diff --git a/tests/patmat/t9289.check b/tests/patmat/t9289.check index 5240988e2606..9a3b61e01189 100644 --- a/tests/patmat/t9289.check +++ b/tests/patmat/t9289.check @@ -1,9 +1,2 @@ -./tests/patmat/t9289.scala:9: warning: match may not be exhaustive. -It would fail on the following input: module.LetR() - def patmat(tree: module.Tree) = tree match { - ^ -./tests/patmat/t9289.scala:20: warning: match may not be exhaustive. -It would fail on the following input: module.LetR() - def patmat(tree: module.Tree) = tree match { - ^ -two warnings found \ No newline at end of file +9: Pattern Match Exhaustivity: module.LetR() +20: Pattern Match Exhaustivity: module.LetR() diff --git a/tests/patmat/t9351.check b/tests/patmat/t9351.check index 03b94c2c001b..bce053c947bd 100644 --- a/tests/patmat/t9351.check +++ b/tests/patmat/t9351.check @@ -1,13 +1,3 @@ -./tests/patmat/t9351.scala:8: warning: match may not be exhaustive. -It would fail on the following input: _: A - a match { - ^ -./tests/patmat/t9351.scala:17: warning: match may not be exhaustive. -It would fail on the following input: (_, _), (_, None), (_, Some(_)) - (a, o) match { - ^ -./tests/patmat/t9351.scala:28: warning: match may not be exhaustive. -It would fail on the following input: (_, _) - (a, b) match { - ^ -three warnings found \ No newline at end of file +8: Pattern Match Exhaustivity: _: A +17: Pattern Match Exhaustivity: (_, _), (_, None), (_, Some(_)) +28: Pattern Match Exhaustivity: (_, _) diff --git a/tests/patmat/t9398.check b/tests/patmat/t9398.check index 0efbf231d6c5..279762d888db 100644 --- a/tests/patmat/t9398.check +++ b/tests/patmat/t9398.check @@ -1,5 +1 @@ -./tests/patmat/t9398.scala:11: warning: match may not be exhaustive. -It would fail on the following input: CC(_, B2) - case CC(_, B) => () - ^ -one warning found +11: Pattern Match Exhaustivity: CC(_, B2) diff --git a/tests/patmat/t9573.check b/tests/patmat/t9573.check index 4ec379161422..70c8e8014f66 100644 --- a/tests/patmat/t9573.check +++ b/tests/patmat/t9573.check @@ -1,5 +1 @@ -./tests/patmat/t9573.scala:9: warning: match may not be exhaustive. -It would fail on the following input: Horse(_) - x match { - ^ -one warning found \ No newline at end of file +9: Pattern Match Exhaustivity: Horse(_) diff --git a/tests/patmat/t9657.check b/tests/patmat/t9657.check index d3e2ec73f494..9b92bee60bbe 100644 --- a/tests/patmat/t9657.check +++ b/tests/patmat/t9657.check @@ -1,17 +1,4 @@ -./tests/patmat/t9657.scala:29: warning: match may not be exhaustive. -It would fail on the following input: Bus(_) - def refuel2[P <: Petrol.type](vehicle: Vehicle {type A = P} ): Vehicle = vehicle match { - ^ -./tests/patmat/t9657.scala:38: warning: match may not be exhaustive. -It would fail on the following input: Bus(_) - def foo2(vehicle: Vehicle {type A <: Petrol.type} ): Vehicle = vehicle match { - ^ -./tests/patmat/t9657.scala:49: warning: match may not be exhaustive. -It would fail on the following input: Bus(_) - def bar2(vehicle: Vehicle {type A <: P} ): Vehicle = vehicle match { - ^ -./tests/patmat/t9657.scala:58: warning: match may not be exhaustive. -It would fail on the following input: Bus(_) - def qux2[P <: Petrol.type](vehicle: Vehicle {type A <: P} ): Vehicle = vehicle match { - ^ -four warnings found \ No newline at end of file +29: Pattern Match Exhaustivity: Bus(_) +38: Pattern Match Exhaustivity: Bus(_) +49: Pattern Match Exhaustivity: Bus(_) +58: Pattern Match Exhaustivity: Bus(_) diff --git a/tests/patmat/t9672.check b/tests/patmat/t9672.check index 3284d1df1e8d..41460e46f0a6 100644 --- a/tests/patmat/t9672.check +++ b/tests/patmat/t9672.check @@ -1,5 +1 @@ -./tests/patmat/t9672.scala:22: warning: match may not be exhaustive. -It would fail on the following input: SimpleExpr.IntExpr(_) - def func(expr: Expr) = expr match { - ^ -one warning found \ No newline at end of file +22: Pattern Match Exhaustivity: SimpleExpr.IntExpr(_) diff --git a/tests/patmat/t9677.check b/tests/patmat/t9677.check index f1e1817cbbaa..3d9e1c4e2bbb 100644 --- a/tests/patmat/t9677.check +++ b/tests/patmat/t9677.check @@ -1,4 +1 @@ -./tests/patmat/t9677.scala:20: warning: unreachable code - case path: A => println("Not root") - ^ -one warning found \ No newline at end of file +20: Match case Unreachable diff --git a/tests/patmat/t9779.check b/tests/patmat/t9779.check index 0e0d8d5f49d1..a7d6cfbead5c 100644 --- a/tests/patmat/t9779.check +++ b/tests/patmat/t9779.check @@ -1,5 +1 @@ -./tests/patmat/t9779.scala:10: warning: match may not be exhaustive. -It would fail on the following input: _: a.Elem - private def toLuaValue(eX: a.Elem[_]): String = eX match { - ^ -one warning found \ No newline at end of file +10: Pattern Match Exhaustivity: _: a.Elem diff --git a/tests/patmat/virtpatmat_apply.check b/tests/patmat/virtpatmat_apply.check index d10d82165a3e..aa4d0b884a7e 100644 --- a/tests/patmat/virtpatmat_apply.check +++ b/tests/patmat/virtpatmat_apply.check @@ -1,5 +1 @@ -./tests/patmat/virtpatmat_apply.scala:2: warning: match may not be exhaustive. -It would fail on the following input: List(_) - List(1, 2, 3) match { - ^ -one warning found \ No newline at end of file +2: Pattern Match Exhaustivity: List(_) diff --git a/tests/patmat/virtpatmat_reach_sealed_unsealed.check b/tests/patmat/virtpatmat_reach_sealed_unsealed.check index ef5ec1a00ccc..6b0ea7f8e1e6 100644 --- a/tests/patmat/virtpatmat_reach_sealed_unsealed.check +++ b/tests/patmat/virtpatmat_reach_sealed_unsealed.check @@ -1,11 +1,3 @@ -./tests/patmat/virtpatmat_reach_sealed_unsealed.scala:16: warning: match may not be exhaustive. -It would fail on the following input: false - (true: Boolean) match { case true => } // not exhaustive, but reachable - ^ -./tests/patmat/virtpatmat_reach_sealed_unsealed.scala:18: warning: unreachable code - (true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable - ^ -./tests/patmat/virtpatmat_reach_sealed_unsealed.scala:19: warning: unreachable code - (true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable - ^ -three warnings found +16: Pattern Match Exhaustivity: false +18: Match case Unreachable +19: Match case Unreachable