From 0416c57a01a2b0feafc340893d64cd54ca7ae84c Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 15 Sep 2020 10:24:32 +0100 Subject: [PATCH] Reverse -Xlint:strict-unsealed-patmat into -Xno-unsealed-patmat-analysis --- project/ScalaOptionParser.scala | 4 +- .../tools/nsc/settings/ScalaSettings.scala | 2 + .../scala/tools/nsc/settings/Warnings.scala | 2 - .../nsc/transform/patmat/MatchAnalysis.scala | 2 +- test/async/jvm/anf.scala | 1 + .../concurrent_GenericTypeBoundaryIssue.check | 0 ...oncurrent_NegativeArraySizeException.scala | 2 +- test/async/jvm/concurrent_shadowing.scala | 1 + test/async/jvm/futures.scala | 1 + test/async/jvm/match0.scala | 1 + test/async/jvm/toughtype.check | 4 +- test/async/jvm/toughtype.scala | 2 + test/async/run/edge-cases.scala | 1 + test/files/jvm/future-spec/FutureTests.scala | 2 +- test/files/jvm/scala-concurrent-tck.scala | 2 +- test/files/jvm/t8786-sig.scala | 2 +- test/files/neg/pat_unreachable.scala | 8 +- test/files/neg/patmat-seq-neg.check | 13 ++ test/files/neg/t10680.check | 11 ++ test/files/{pos => neg}/t10680.scala | 0 test/files/neg/t11102.check | 21 +++ test/files/neg/t11746.check | 6 +- test/files/neg/t1183.scala | 2 +- test/files/neg/t2910.check | 4 +- test/files/neg/t2910.scala | 2 +- test/files/neg/t4440.scala | 4 +- test/files/neg/t5365c.scala | 2 +- test/files/neg/t5830.scala | 2 +- test/files/neg/t5898.check | 6 +- test/files/neg/t6011.check | 4 +- test/files/neg/t6011.scala | 1 + test/files/neg/t6048.check | 4 +- test/files/neg/t6048.scala | 6 +- test/files/neg/t6675.check | 2 +- test/files/neg/t6675.scala | 4 +- test/files/neg/t7623.scala | 2 +- test/files/neg/t8597.scala | 2 +- test/files/neg/t8597b.scala | 2 +- test/files/neg/t8731.scala | 2 +- test/files/neg/tailrec-4.check | 10 +- test/files/neg/tailrec-4.scala | 1 + test/files/neg/unchecked-refinement.check | 6 +- test/files/neg/unchecked3.scala | 2 +- .../files/neg/virtpatmat_unreach_select.check | 6 +- test/files/pos/t10373.scala | 2 +- test/files/pos/t1439.scala | 1 + test/files/pos/t4911.scala | 6 +- test/files/pos/t5029.scala | 2 +- test/files/pos/t6022.scala | 1 + test/files/presentation/doc/doc.scala | 1 + test/files/run/Course-2002-07.scala | 8 +- test/files/run/caseclasses.scala | 1 + test/files/run/existentials.scala | 6 +- test/files/run/gadts.scala | 2 +- .../Test_2.scala | 1 + .../Test_2.scala | 1 + .../macro-rangepos-subpatterns/Test_2.scala | 1 + test/files/run/macro-subpatterns/Test_2.scala | 1 + .../Macros_1.scala | 2 +- .../run/macro-whitebox-extractor/Test_2.scala | 1 + test/files/run/manifests-new.scala | 1 + test/files/run/manifests-old.scala | 1 + test/files/run/matchemptyarray.scala | 1 + test/files/run/matchonstream.check | 3 + test/files/run/patmat-behavior.check | 42 ++++++ test/files/run/patmatnew.check | 39 ++++++ .../run/pure-warning-post-macro/Macro_1.scala | 1 + .../run/reflection-valueclasses-magic.scala | 1 + test/files/run/sd187.check | 38 +++--- test/files/run/sd187.scala | 4 +- test/files/run/string-switch.scala | 3 +- test/files/run/t10067/Test.scala | 1 + test/files/run/t1434.scala | 1 + test/files/run/t1503.scala | 4 +- test/files/run/t2577.scala | 1 + test/files/run/t3050.scala | 2 +- test/files/run/t3150.scala | 2 +- test/files/run/t3395.scala | 2 + test/files/run/t3702.scala | 1 + test/files/run/t3888.check | 0 test/files/run/t4025.check | 2 +- test/files/run/t4025.scala | 2 +- test/files/run/t4415.scala | 1 + test/files/run/t4482.scala | 2 +- test/files/run/t4897.scala | 2 +- test/files/run/t5612.scala | 1 + test/files/run/t5688.scala | 2 +- test/files/run/t5704.scala | 1 + test/files/run/t576.scala | 1 + test/files/run/t5830.scala | 2 +- test/files/run/t5903b/Test_2.scala | 1 + test/files/run/t5903c/Test_2.scala | 1 + test/files/run/t5903d/Test_2.scala | 1 + test/files/run/t5914.scala | 1 + test/files/run/t6011b.scala | 2 +- .../run/t6077_patmat_cse_irrefutable.scala | 1 + test/files/run/t6104.scala | 1 + test/files/run/t6111.scala | 4 +- test/files/run/t6288.check | 121 +++++++++--------- test/files/run/t6288.scala | 3 + test/files/run/t6695.scala | 2 + test/files/run/t6863.scala | 1 + test/files/run/t7214.scala | 1 + test/files/run/t7912.scala | 1 + test/files/run/t8611a.scala | 1 + test/files/run/t8611c.scala | 1 + test/files/run/t8637.check | 0 test/files/run/t8888.scala | 2 + test/files/run/t9003.check | 2 +- test/files/run/t9003.scala | 1 + test/files/run/t9029b.scala | 1 + test/files/run/t9029c.scala | 2 + test/files/run/t9110.scala | 1 + test/files/run/t9408.scala | 2 + test/files/run/t9644.check | 6 + test/files/run/tailcalls.scala | 1 + test/files/run/typecheck.check | 0 test/files/run/unapply.check | 5 +- test/files/run/unapply.scala | 11 +- test/files/run/unapplyArray.check | 3 + test/files/run/uncheckedStable.check | 4 + test/files/run/virtpatmat_literal.check | 6 + test/files/run/virtpatmat_literal.scala | 3 + test/files/run/virtpatmat_npe.check | 2 +- test/files/run/virtpatmat_npe.scala | 1 + test/files/run/virtpatmat_switch.check | 2 +- test/files/run/virtpatmat_switch.scala | 2 +- test/files/run/virtpatmat_typed.scala | 1 + test/files/run/virtpatmat_unapply.scala | 2 + .../nsc/async/AnnotationDrivenAsyncTest.scala | 1 + .../backend/jvm/OptimizedBytecodeTest.scala | 1 + .../backend/jvm/opt/UnreachableCodeTest.scala | 2 +- .../transform/patmat/PatmatBytecodeTest.scala | 1 + test/scaladoc/run/t191.check | 2 +- test/scaladoc/run/t191.scala | 1 + test/scaladoc/run/tables.scala | 1 + .../run/src-2/tastytest/TestExports.scala | 1 + .../src-2/tastytest/TestFancyColours.scala | 4 + .../run/src-2/tastytest/TestTermRefIns.scala | 1 + 139 files changed, 420 insertions(+), 163 deletions(-) delete mode 100644 test/async/jvm/concurrent_GenericTypeBoundaryIssue.check create mode 100644 test/files/neg/t10680.check rename test/files/{pos => neg}/t10680.scala (100%) delete mode 100644 test/files/run/t3888.check delete mode 100644 test/files/run/t8637.check create mode 100644 test/files/run/t9644.check delete mode 100644 test/files/run/typecheck.check create mode 100644 test/files/run/unapplyArray.check create mode 100644 test/files/run/uncheckedStable.check diff --git a/project/ScalaOptionParser.scala b/project/ScalaOptionParser.scala index 0a0f5951af..64506b406e 100644 --- a/project/ScalaOptionParser.scala +++ b/project/ScalaOptionParser.scala @@ -83,7 +83,7 @@ object ScalaOptionParser { // TODO retrieve these data programmatically, ala https://github.com/scala/scala-tool-support/blob/master/bash-completion/src/main/scala/BashCompletion.scala private def booleanSettingNames = List("-X", "-Xasync", "-Xcheckinit", "-Xdev", "-Xdisable-assertions", "-Xexperimental", "-Xfatal-warnings", "-Xlog-free-terms", "-Xlog-free-types", "-Xlog-implicit-conversions", "-Xlog-implicits", "-Xlog-reflective-calls", - "-Xno-forwarders", "-Xno-patmat-analysis", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y", + "-Xno-forwarders", "-Xno-patmat-analysis", "-Xno-unsealed-patmat-analysis", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y", "-Ybreak-cycles", "-Ydebug", "-Ycompact-trees", "-YdisableFlatCpCaching", "-Ydoc-debug", "-Yide-debug", "-Yissue-debug", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand", @@ -108,7 +108,7 @@ object ScalaOptionParser { "-g" -> List("line", "none", "notailcails", "source", "vars"), "-target" -> targetSettingNames) private def multiChoiceSettingNames = Map[String, List[String]]( - "-Xlint" -> List("adapted-args", "nullary-unit", "inaccessible", "nullary-override", "infer-any", "missing-interpolator", "doc-detached", "private-shadow", "type-parameter-shadow", "poly-implicit-overload", "option-implicit", "delayedinit-select", "package-object-classes", "stars-align", "strict-unsealed-patmat", "constant", "unused", "eta-zero"), + "-Xlint" -> List("adapted-args", "nullary-unit", "inaccessible", "nullary-override", "infer-any", "missing-interpolator", "doc-detached", "private-shadow", "type-parameter-shadow", "poly-implicit-overload", "option-implicit", "delayedinit-select", "package-object-classes", "stars-align", "constant", "unused", "eta-zero"), "-language" -> List("help", "_", "dynamics", "postfixOps", "reflectiveCalls", "implicitConversions", "higherKinds", "existentials", "experimental.macros"), "-opt" -> List("unreachable-code", "simplify-jumps", "compact-locals", "copy-propagation", "redundant-casts", "box-unbox", "nullness-tracking", "closure-invocations" , "allow-skip-core-module-init", "assume-modules-non-null", "allow-skip-class-loading", "inline", "l:none", "l:default", "l:method", "l:inline", "l:project", "l:classpath"), "-Ywarn-unused" -> List("imports", "patvars", "privates", "locals", "explicits", "implicits", "params"), diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 5966c5ad26..cfb53ffba5 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -168,6 +168,8 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett def isAtLeastJunit = isTruthy || XmixinForceForwarders.value == "junit" } + val noUnsealedPatmatAnalysis = BooleanSetting("-Xno-unsealed-patmat-analysis", "Pattern match on an unsealed class without a catch-all.") + // XML parsing options object XxmlSettings extends MultiChoiceEnumeration { val coalescing = Choice("coalescing", "Convert PCData to Text and coalesce sibling nodes") diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala index b5bf4532f2..dff304d8ba 100644 --- a/src/compiler/scala/tools/nsc/settings/Warnings.scala +++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala @@ -176,7 +176,6 @@ trait Warnings { val DelayedInitSelect = LintWarning("delayedinit-select", "Selecting member of DelayedInit.") val PackageObjectClasses = LintWarning("package-object-classes", "Class or object defined in package object.") val StarsAlign = LintWarning("stars-align", "In a pattern, a sequence wildcard `_*` should match all of a repeated parameter.") - val StrictUnsealedPatMat = LintWarning("strict-unsealed-patmat", "Pattern match on an unsealed class without a catch-all.") val Constant = LintWarning("constant", "Evaluation of a constant arithmetic expression resulted in an error.") val Unused = LintWarning("unused", "Enable -Wunused:imports,privates,locals,implicits,nowarn.") val NonlocalReturn = LintWarning("nonlocal-return", "A return statement used an exception for flow control.") @@ -208,7 +207,6 @@ trait Warnings { def warnOptionImplicit = lint contains OptionImplicit def warnDelayedInit = lint contains DelayedInitSelect def warnPackageObjectClasses = lint contains PackageObjectClasses - def warnStrictUnsealedPatMat = lint contains StrictUnsealedPatMat def warnStarsAlign = lint contains StarsAlign def warnConstant = lint contains Constant def lintUnused = lint contains Unused diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala index e42dda8d50..c6cfeb99af 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala @@ -498,7 +498,7 @@ trait MatchAnalysis extends MatchApproximation { // exhaustivity - def exhaustive(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): List[String] = if (!settings.warnStrictUnsealedPatMat && uncheckableType(prevBinder.info)) Nil else { + def exhaustive(prevBinder: Symbol, cases: List[List[TreeMaker]], pt: Type): List[String] = if (settings.noUnsealedPatmatAnalysis && uncheckableType(prevBinder.info)) Nil else { // customize TreeMakersToProps (which turns a tree of tree makers into a more abstract DAG of tests) // - approximate the pattern `List()` (unapplySeq on List with empty length) as `Nil`, // otherwise the common (xs: List[Any]) match { case List() => case x :: xs => } is deemed unexhaustive diff --git a/test/async/jvm/anf.scala b/test/async/jvm/anf.scala index 7a4cc05a3c..63e6aa8053 100644 --- a/test/async/jvm/anf.scala +++ b/test/async/jvm/anf.scala @@ -387,6 +387,7 @@ package scala.async.run.anf { await(fut(1)) match { case Up => 1.0 case Down => -1.0 + case x => throw new MatchError(x) } } sign.block mustBe 1.0 diff --git a/test/async/jvm/concurrent_GenericTypeBoundaryIssue.check b/test/async/jvm/concurrent_GenericTypeBoundaryIssue.check deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/async/jvm/concurrent_NegativeArraySizeException.scala b/test/async/jvm/concurrent_NegativeArraySizeException.scala index 3575463be2..9cda7fa26d 100644 --- a/test/async/jvm/concurrent_NegativeArraySizeException.scala +++ b/test/async/jvm/concurrent_NegativeArraySizeException.scala @@ -9,7 +9,7 @@ object Test extends App { test() def foo(foo: Any, bar: Any) = () def getValue = async {4.2} def func(f: Any) = async { - foo(f match { case _ if "".isEmpty => 2 }, await(getValue)); + foo(f match { case _ if "".isEmpty => 2 case x => throw new MatchError(x) }, await(getValue)); } def test() = Await.result(func(4), Duration.Inf) diff --git a/test/async/jvm/concurrent_shadowing.scala b/test/async/jvm/concurrent_shadowing.scala index 6d6ee69ce2..8918096d4d 100644 --- a/test/async/jvm/concurrent_shadowing.scala +++ b/test/async/jvm/concurrent_shadowing.scala @@ -20,6 +20,7 @@ object Test extends App { test case _ => foo; () } () + case x => throw new MatchError(x) } () }, Duration.Inf) diff --git a/test/async/jvm/futures.scala b/test/async/jvm/futures.scala index 326d517e01..55ebd4c8a6 100644 --- a/test/async/jvm/futures.scala +++ b/test/async/jvm/futures.scala @@ -85,6 +85,7 @@ package scala.async.run.futures { case "Hello" => Future { "World" } case "Failure" => Future.failed(new RuntimeException("Expected exception; to test fault-tolerance")) case "NoReply" => Promise[String]().future + case x => throw new MatchError(x) } val defaultTimeout = 5 seconds diff --git a/test/async/jvm/match0.scala b/test/async/jvm/match0.scala index fed61dee26..9916df5edd 100644 --- a/test/async/jvm/match0.scala +++ b/test/async/jvm/match0.scala @@ -119,6 +119,7 @@ package scala.async.run.match0 { await(0) case buf: Double => await(2) + case x => throw new MatchError(x) } }) diff --git a/test/async/jvm/toughtype.check b/test/async/jvm/toughtype.check index 47f57a5fb1..1de9501259 100644 --- a/test/async/jvm/toughtype.check +++ b/test/async/jvm/toughtype.check @@ -1,6 +1,6 @@ -toughtype.scala:173: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected +toughtype.scala:175: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected identity[A] _ ^ -toughtype.scala:173: warning: a pure expression does nothing in statement position +toughtype.scala:175: warning: a pure expression does nothing in statement position identity[A] _ ^ diff --git a/test/async/jvm/toughtype.scala b/test/async/jvm/toughtype.scala index cfd0bbd6d2..939d0647e9 100644 --- a/test/async/jvm/toughtype.scala +++ b/test/async/jvm/toughtype.scala @@ -76,6 +76,7 @@ package scala.async.run.toughtype { var ss = s ss = s await(x) + case x => throw new MatchError(x) } }) assertEquals(0, m7(Nil)) @@ -114,6 +115,7 @@ package scala.async.run.toughtype { val foo = await(5) val e0 = buf(0) ContainerImpl(e0) + case x => throw new MatchError(x) } }) foo diff --git a/test/async/run/edge-cases.scala b/test/async/run/edge-cases.scala index 0500c5c2d7..4306570dc6 100644 --- a/test/async/run/edge-cases.scala +++ b/test/async/run/edge-cases.scala @@ -34,6 +34,7 @@ object Test { value(Some(1)) "foo" match { case x if "".isEmpty => x + case x => throw new MatchError(x) } }: AnyRef }) diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index cc31ce463b..f2c83a64ae 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -11,7 +11,7 @@ class FutureTests extends MinimalScalaTest { /* some utils */ - def testAsync(s: String)(implicit ec: ExecutionContext): Future[String] = s match { + def testAsync(s: String)(implicit ec: ExecutionContext): Future[String] = (s: @unchecked) match { case "Hello" => Future { "World" } case "Failure" => Future.failed(new RuntimeException("Expected exception; to test fault-tolerance")) case "NoReply" => Promise[String]().future diff --git a/test/files/jvm/scala-concurrent-tck.scala b/test/files/jvm/scala-concurrent-tck.scala index 6438172278..bcbd977e01 100644 --- a/test/files/jvm/scala-concurrent-tck.scala +++ b/test/files/jvm/scala-concurrent-tck.scala @@ -225,7 +225,7 @@ def testTransformFailure(): Unit = once { val e = new Exception("expected") val transformed = new Exception("transformed") val f = Future[Unit] { throw e } - val g = f.transform(identity, { case `e` => transformed }) + val g = f.transform(identity, (_: Throwable @unchecked) match { case `e` => transformed }) g onComplete { case Success(_) => done(false) case Failure(e) => done(e eq transformed) diff --git a/test/files/jvm/t8786-sig.scala b/test/files/jvm/t8786-sig.scala index 9d50775a55..d9fdac7586 100644 --- a/test/files/jvm/t8786-sig.scala +++ b/test/files/jvm/t8786-sig.scala @@ -25,7 +25,7 @@ object Test extends App { def genSig(method: String, tp: Class[_]) = a.getDeclaredMethod(method, tp).toGenericString def bound (method: String, tp: Class[_]) = { val m = a.getDeclaredMethod(method, tp) - m.getGenericParameterTypes.apply(0) match { + (m.getGenericParameterTypes.apply(0): @unchecked) match { case _: Class[_] => "" case gat: java.lang.reflect.GenericArrayType => val compTp = gat.getGenericComponentType.asInstanceOf[java.lang.reflect.TypeVariable[_]] diff --git a/test/files/neg/pat_unreachable.scala b/test/files/neg/pat_unreachable.scala index 8e296d3e35..cd5acfd093 100644 --- a/test/files/neg/pat_unreachable.scala +++ b/test/files/neg/pat_unreachable.scala @@ -2,20 +2,20 @@ // object Test extends App { - def unreachable1(xs:Seq[Char]) = xs match { + def unreachable1(xs:Seq[Char]) = (xs: @unchecked) match { case Seq(x, y, _*) => x::y::Nil case Seq(x, y, z, w) => List(z,w) // redundant! } - def unreachable2(xs:Seq[Char]) = xs match { + def unreachable2(xs:Seq[Char]) = (xs: @unchecked) match { case Seq(x, y, _*) => x::y::Nil case Seq(x, y) => List(x, y) } - def not_unreachable(xs:Seq[Char]) = xs match { + def not_unreachable(xs:Seq[Char]) = (xs: @unchecked) match { case Seq(x, y, _*) => x::y::Nil case Seq(x) => List(x) } - def not_unreachable2(xs:Seq[Char]) = xs match { + def not_unreachable2(xs:Seq[Char]) = (xs: @unchecked) match { case Seq(x, y) => x::y::Nil case Seq(x, y, z, _*) => List(x,y) } diff --git a/test/files/neg/patmat-seq-neg.check b/test/files/neg/patmat-seq-neg.check index 2297f1efbb..a1eb5d9630 100644 --- a/test/files/neg/patmat-seq-neg.check +++ b/test/files/neg/patmat-seq-neg.check @@ -1,3 +1,9 @@ +patmat-seq-neg.scala:12: warning: match may not be exhaustive. + def t2: Any = 2 match { + ^ +patmat-seq-neg.scala:15: warning: match may not be exhaustive. + def t3: Any = 2 match { + ^ patmat-seq-neg.scala:15: error: error during expansion of this match (this is a scalac bug). The underlying error was: type mismatch; found : scala.collection.mutable.ArrayBuffer[Int] @@ -8,8 +14,15 @@ patmat-seq-neg.scala:18: error: error during expansion of this match (this is a The underlying error was: value toSeq is not a member of Array[Int] def t4: Any = 2 match { ^ +patmat-seq-neg.scala:21: warning: match may not be exhaustive. + def t5: Any = 2 match { + ^ +patmat-seq-neg.scala:24: warning: match may not be exhaustive. + def t6: Any = 2 match { + ^ patmat-seq-neg.scala:24: error: error during expansion of this match (this is a scalac bug). The underlying error was: value drop is not a member of Array[Int] def t6: Any = 2 match { ^ +4 warnings 3 errors diff --git a/test/files/neg/t10680.check b/test/files/neg/t10680.check new file mode 100644 index 0000000000..74f507b001 --- /dev/null +++ b/test/files/neg/t10680.check @@ -0,0 +1,11 @@ +t10680.scala:13: warning: match may not be exhaustive. +It would fail on the following input: (x: MyEnum.Value forSome x not in (e1, e2)) + def fn(e: MyEnum.Value) = e match { + ^ +t10680.scala:18: warning: match may not be exhaustive. +It would fail on the following inputs: (Value(), _), (_, Value()), (_, _) + def fn2(e: MyEnum.Value, o: MyOtherEnum.Value) = (e, o) match { + ^ +error: No warnings can be incurred under -Werror. +2 warnings +1 error diff --git a/test/files/pos/t10680.scala b/test/files/neg/t10680.scala similarity index 100% rename from test/files/pos/t10680.scala rename to test/files/neg/t10680.scala diff --git a/test/files/neg/t11102.check b/test/files/neg/t11102.check index b23c79e154..c96a6db48f 100644 --- a/test/files/neg/t11102.check +++ b/test/files/neg/t11102.check @@ -1,13 +1,34 @@ +t11102.scala:2: warning: match may not be exhaustive. +It would fail on the following input: (x: ImmutableSeq forSome x not in ImmutableCons) + def f(x: ImmutableSeq) = x match { + ^ +t11102.scala:5: warning: match may not be exhaustive. +It would fail on the following input: (x: MutableSeq forSome x not in MutableCons) + def f(x: MutableSeq) = x match { + ^ t11102.scala:5: error: error during expansion of this match (this is a scalac bug). The underlying error was: type mismatch; found : Seq[MutableCons] (in scala.collection.mutable) required: Seq[MutableCons] (in scala.collection.immutable) def f(x: MutableSeq) = x match { ^ +t11102.scala:8: warning: match may not be exhaustive. +It would fail on the following input: (x: CollectionSeq forSome x not in CollectionCons) + def f(x: CollectionSeq) = x match { + ^ t11102.scala:8: error: error during expansion of this match (this is a scalac bug). The underlying error was: type mismatch; found : Seq[CollectionCons] (in scala.collection) required: Seq[CollectionCons] (in scala.collection.immutable) def f(x: CollectionSeq) = x match { ^ +t11102.scala:11: warning: match may not be exhaustive. +It would fail on the following input: (x: ScalaSeq forSome x not in ScalaCons) + def f(x: ScalaSeq) = x match { + ^ +t11102.scala:14: warning: match may not be exhaustive. +It would fail on the following input: (x: DefaultSeq forSome x not in DefaultCons) + def f(x: DefaultSeq) = x match { + ^ +5 warnings 2 errors diff --git a/test/files/neg/t11746.check b/test/files/neg/t11746.check index a7334117cd..040c41563b 100644 --- a/test/files/neg/t11746.check +++ b/test/files/neg/t11746.check @@ -1,7 +1,11 @@ +t11746.scala:16: warning: match may not be exhaustive. +It would fail on the following input: (x: Try forSome x not in Failure) + private def get(a: String): Unit = Try(a) match { + ^ t11746.scala:18: warning: failed to determine if e should be inlined: The method e()Ljava/lang/Throwable; could not be found in the class java/lang/Object or any of its parents. case Failure(e) => println(e.toString) ^ error: No warnings can be incurred under -Werror. -1 warning +2 warnings 1 error diff --git a/test/files/neg/t1183.scala b/test/files/neg/t1183.scala index 23868ab401..cbd6348af6 100644 --- a/test/files/neg/t1183.scala +++ b/test/files/neg/t1183.scala @@ -14,7 +14,7 @@ object Test { val foo1 = new Foo(1) def runTest() = { - val res = (foo1.Bar(2):Any) match { + val res = (foo1.Bar(2):Any @unchecked) match { case foo1.Bar(2) => true // (1) } require(res) diff --git a/test/files/neg/t2910.check b/test/files/neg/t2910.check index 716bd5e630..cdf36f9eaa 100644 --- a/test/files/neg/t2910.check +++ b/test/files/neg/t2910.check @@ -1,6 +1,6 @@ t2910.scala:3: error: forward reference extends over definition of value ret - val ret = l.map({ case MyMatch(id) => id }) - ^ + val ret = l.collect({ case MyMatch(id) => id }) + ^ t2910.scala:9: error: forward reference extends over definition of value z println(s.length) ^ diff --git a/test/files/neg/t2910.scala b/test/files/neg/t2910.scala index f2ce3718c9..d8446eb93f 100644 --- a/test/files/neg/t2910.scala +++ b/test/files/neg/t2910.scala @@ -1,6 +1,6 @@ object Junk { def f(l: List[String]): List[String] = { - val ret = l.map({ case MyMatch(id) => id }) + val ret = l.collect({ case MyMatch(id) => id }) val MyMatch = "(\\d+)".r ret } diff --git a/test/files/neg/t4440.scala b/test/files/neg/t4440.scala index 85d0c3ae9a..8fe7346e31 100644 --- a/test/files/neg/t4440.scala +++ b/test/files/neg/t4440.scala @@ -10,11 +10,11 @@ class Outer { final class Inner } object Test extends App { val a = new Outer val b = new Outer - (new a.Inner: Any) match { + (new a.Inner: Any @unchecked) match { case _: b.Inner => println("b") case _: a.Inner => println("a") // this is the case we want } - (new b.Inner: Any) match { + (new b.Inner: Any @unchecked) match { case _: a.Inner => println("a") case _: b.Inner => println("b") // this is the case we want } diff --git a/test/files/neg/t5365c.scala b/test/files/neg/t5365c.scala index d79cd905c0..f407296dca 100644 --- a/test/files/neg/t5365c.scala +++ b/test/files/neg/t5365c.scala @@ -1,4 +1,4 @@ -// scalac: -Xfatal-warnings -Xlint:strict-unsealed-patmat +// scalac: -Xfatal-warnings object C { trait Z final case class Q(i: Int) extends Z diff --git a/test/files/neg/t5830.scala b/test/files/neg/t5830.scala index 3074273af0..9c46e2bcd9 100644 --- a/test/files/neg/t5830.scala +++ b/test/files/neg/t5830.scala @@ -6,6 +6,6 @@ class Test { def unreachable(ch: Char) = (ch: @switch) match { case 'a' => println("b") // ok case 'a' => println("b") // unreachable - case 'c' => + case _ => } } diff --git a/test/files/neg/t5898.check b/test/files/neg/t5898.check index 9c9e7f2019..6dc1a13d5a 100644 --- a/test/files/neg/t5898.check +++ b/test/files/neg/t5898.check @@ -6,6 +6,10 @@ t5898.scala:10: warning: match may not be exhaustive. It would fail on the following input: C(_) val D(x) = t ^ +t5898.scala:11: warning: match may not be exhaustive. +It would fail on the following input: (x: Any forSome x not in D) + val D(y) = (null: Any) + ^ error: No warnings can be incurred under -Werror. -2 warnings +3 warnings 1 error diff --git a/test/files/neg/t6011.check b/test/files/neg/t6011.check index 95d4dd55b3..a3e2da5d25 100644 --- a/test/files/neg/t6011.check +++ b/test/files/neg/t6011.check @@ -1,10 +1,10 @@ t6011.scala:6: warning: unreachable code case 'a' | 'c' => 1 // unreachable ^ -t6011.scala:12: warning: unreachable code +t6011.scala:13: warning: unreachable code case 'b' | 'a' => 1 // unreachable ^ -t6011.scala:10: warning: could not emit switch for @switch annotated match +t6011.scala:11: warning: could not emit switch for @switch annotated match def f2(ch: Char): Any = (ch: @annotation.switch) match { ^ error: No warnings can be incurred under -Werror. diff --git a/test/files/neg/t6011.scala b/test/files/neg/t6011.scala index 7bc26ebaff..3cd7f7c625 100644 --- a/test/files/neg/t6011.scala +++ b/test/files/neg/t6011.scala @@ -4,6 +4,7 @@ object Test { def f(ch: Char): Any = ch match { case 'a' => 1 case 'a' | 'c' => 1 // unreachable + case _ => throw new MatchError(ch) } // won't be compiled to a switch since it has an unreachable (duplicate) case diff --git a/test/files/neg/t6048.check b/test/files/neg/t6048.check index fe79e08333..f5a9e1400f 100644 --- a/test/files/neg/t6048.check +++ b/test/files/neg/t6048.check @@ -8,10 +8,10 @@ t6048.scala:15: warning: patterns after a variable pattern cannot match (SLS 8.1 case _ => x ^ t6048.scala:16: warning: unreachable code due to variable pattern on line 15 - case 5 if true => x // unreachable + case _ if true => x // unreachable ^ t6048.scala:16: warning: unreachable code - case 5 if true => x // unreachable + case _ if true => x // unreachable ^ error: No warnings can be incurred under -Werror. 5 warnings diff --git a/test/files/neg/t6048.scala b/test/files/neg/t6048.scala index fa7b94be26..e21bfeee08 100644 --- a/test/files/neg/t6048.scala +++ b/test/files/neg/t6048.scala @@ -3,17 +3,17 @@ class A { def f1(x: Int) = x match { case _ if false => x // unreachable - case 5 => x + case _ => x } def f2(x: Int) = x match { case _ if false => x // unreachable - case 5 if true => x + case _ if true => x } def f3(x: Int) = x match { case _ => x - case 5 if true => x // unreachable + case _ if true => x // unreachable } def test1(x: Int) = x match { diff --git a/test/files/neg/t6675.check b/test/files/neg/t6675.check index f07dbb4dba..dad3f61cf1 100644 --- a/test/files/neg/t6675.check +++ b/test/files/neg/t6675.check @@ -1,5 +1,5 @@ t6675.scala:12: warning: deprecated adaptation: object X expects 3 patterns to hold (Int, Int, Int) but crushing into 3-tuple to fit single pattern (scala/bug#6675) - "" match { case X(b) => b } // should warn under -Xlint. Not an error because of scala/bug#6111 + "" match { case X(b) => b case x => throw new MatchError(x) } // should warn under -Xlint. Not an error because of scala/bug#6111 ^ error: No warnings can be incurred under -Werror. 1 warning diff --git a/test/files/neg/t6675.scala b/test/files/neg/t6675.scala index 18dbd954c8..879fc6d5a4 100644 --- a/test/files/neg/t6675.scala +++ b/test/files/neg/t6675.scala @@ -9,7 +9,7 @@ object Y { } object Test { - "" match { case X(b) => b } // should warn under -Xlint. Not an error because of scala/bug#6111 + "" match { case X(b) => b case x => throw new MatchError(x) } // should warn under -Xlint. Not an error because of scala/bug#6111 - "" match { case Y(b) => b } // no warning + "" match { case Y(b) => b case x => throw new MatchError(x) } // no warning } diff --git a/test/files/neg/t7623.scala b/test/files/neg/t7623.scala index fb36d0b5d7..8eac860ea4 100644 --- a/test/files/neg/t7623.scala +++ b/test/files/neg/t7623.scala @@ -1,4 +1,4 @@ -// scalac: -Xlint:stars-align -Xfatal-warnings +// scalac: -Xlint:stars-align -Xfatal-warnings -Xno-unsealed-patmat-analysis // diff --git a/test/files/neg/t8597.scala b/test/files/neg/t8597.scala index b5925c48a1..6d54ffe45d 100644 --- a/test/files/neg/t8597.scala +++ b/test/files/neg/t8597.scala @@ -1,4 +1,4 @@ -// scalac: -Xfatal-warnings +// scalac: -Xfatal-warnings -Xno-unsealed-patmat-analysis // class Unchecked[C] { def nowarn[T] = (null: Any) match { case _: Some[T] => } // warn (did not warn due to scala/bug#8597) diff --git a/test/files/neg/t8597b.scala b/test/files/neg/t8597b.scala index 26b3f97c15..07bc43ee44 100644 --- a/test/files/neg/t8597b.scala +++ b/test/files/neg/t8597b.scala @@ -1,4 +1,4 @@ -// scalac: -Xfatal-warnings +// scalac: -Xfatal-warnings -Xno-unsealed-patmat-analysis // object Unchecked { (null: Any) match { diff --git a/test/files/neg/t8731.scala b/test/files/neg/t8731.scala index fd85fbe42a..903a5108be 100644 --- a/test/files/neg/t8731.scala +++ b/test/files/neg/t8731.scala @@ -1,4 +1,4 @@ -// scalac: -Xfatal-warnings +// scalac: -Xfatal-warnings -Xno-unsealed-patmat-analysis // class C { // not a compile-time constant due to return type diff --git a/test/files/neg/tailrec-4.check b/test/files/neg/tailrec-4.check index 0b2df62c6c..4f0a182154 100644 --- a/test/files/neg/tailrec-4.check +++ b/test/files/neg/tailrec-4.check @@ -1,16 +1,16 @@ -tailrec-4.scala:6: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position +tailrec-4.scala:7: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position @tailrec def foo: Int = foo + 1 ^ -tailrec-4.scala:11: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position +tailrec-4.scala:12: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position @tailrec def foo: Int = foo + 1 ^ -tailrec-4.scala:17: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position +tailrec-4.scala:18: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position @tailrec def foo: Int = foo + 1 ^ -tailrec-4.scala:23: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position +tailrec-4.scala:24: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position @tailrec def foo: Int = foo + 1 ^ -tailrec-4.scala:31: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position +tailrec-4.scala:32: error: could not optimize @tailrec annotated method foo: it contains a recursive call not in tail position @tailrec def foo: Int = foo + 1 ^ 5 errors diff --git a/test/files/neg/tailrec-4.scala b/test/files/neg/tailrec-4.scala index 90dad3c865..a1fc8b5f78 100644 --- a/test/files/neg/tailrec-4.scala +++ b/test/files/neg/tailrec-4.scala @@ -1,3 +1,4 @@ +// scalac: -Xno-unsealed-patmat-analysis import annotation._ object Tail { diff --git a/test/files/neg/unchecked-refinement.check b/test/files/neg/unchecked-refinement.check index 95dcec0c89..b24a7d27c3 100644 --- a/test/files/neg/unchecked-refinement.check +++ b/test/files/neg/unchecked-refinement.check @@ -10,11 +10,15 @@ unchecked-refinement.scala:25: warning: a pattern match on a refinement type is unchecked-refinement.scala:26: warning: a pattern match on a refinement type is unchecked /* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn ^ +unchecked-refinement.scala:18: warning: match may not be exhaustive. +It would fail on the following input: ?? + def f3[T, U, V](x: Foo[T, U, V]) = x match { + ^ unchecked-refinement.scala:24: warning: match may not be exhaustive. It would fail on the following inputs: List(_), Nil def f4(xs: List[Int]) = xs match { ^ warning: 1 feature warning; re-run with -feature for details error: No warnings can be incurred under -Werror. -6 warnings +7 warnings 1 error diff --git a/test/files/neg/unchecked3.scala b/test/files/neg/unchecked3.scala index c8b6362339..abb73b5efc 100644 --- a/test/files/neg/unchecked3.scala +++ b/test/files/neg/unchecked3.scala @@ -1,4 +1,4 @@ -// scalac: -Xfatal-warnings +// scalac: -Xfatal-warnings -Xno-unsealed-patmat-analysis // sealed trait A2[T1] final class B2[T1, T2] extends A2[T1] diff --git a/test/files/neg/virtpatmat_unreach_select.check b/test/files/neg/virtpatmat_unreach_select.check index 7b24eda8df..24dfbf3245 100644 --- a/test/files/neg/virtpatmat_unreach_select.check +++ b/test/files/neg/virtpatmat_unreach_select.check @@ -1,6 +1,10 @@ virtpatmat_unreach_select.scala:12: warning: unreachable code case WARNING.id => // unreachable ^ +virtpatmat_unreach_select.scala:9: warning: match may not be exhaustive. +It would fail on the following input: (x: Int forSome x not in (id, id)) + (0: Int) match { + ^ error: No warnings can be incurred under -Werror. -1 warning +2 warnings 1 error diff --git a/test/files/pos/t10373.scala b/test/files/pos/t10373.scala index fc285faef0..f1c62ec072 100644 --- a/test/files/pos/t10373.scala +++ b/test/files/pos/t10373.scala @@ -1,5 +1,5 @@ // scalac: -Werror -abstract class Foo { +sealed abstract class Foo { def bar(): Unit = this match { case Foo_1() => //do something case Foo_2() => //do something diff --git a/test/files/pos/t1439.scala b/test/files/pos/t1439.scala index 6944079dc8..baef9d60d0 100644 --- a/test/files/pos/t1439.scala +++ b/test/files/pos/t1439.scala @@ -6,5 +6,6 @@ class View[C[A]] { } object Test { (null: Any) match { case v: View[_] => + case _ => } } diff --git a/test/files/pos/t4911.scala b/test/files/pos/t4911.scala index b5caeec968..ba2daa367d 100644 --- a/test/files/pos/t4911.scala +++ b/test/files/pos/t4911.scala @@ -6,11 +6,11 @@ import language._ object Test { class Foo[T](val x: T) ; object Foo { def unapply[T](x: Foo[T]) = Some(x.x) } def f1[T](x: Foo[T]) = x match { case Foo(y) => y } - def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y } + def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y case _ => throw new MatchError(x) } case class Bar[T](x: T) - def f3[T](x: Bar[T]) = x match { case Bar(y) => y } - def f4[M[_], T](x: M[T]) = x match { case Bar(y) => y } + def f3[T](x: Bar[T]) = x match { case Bar(y) => y case _ => throw new MatchError(x) } + def f4[M[_], T](x: M[T]) = x match { case Bar(y) => y case _ => throw new MatchError(x) } } // // ./b.scala:4: warning: non variable type-argument T in type pattern Test.Foo[T] is unchecked since it is eliminated by erasure diff --git a/test/files/pos/t5029.scala b/test/files/pos/t5029.scala index f88551f072..c8af164c1d 100644 --- a/test/files/pos/t5029.scala +++ b/test/files/pos/t5029.scala @@ -1,5 +1,5 @@ // scalac: -Xfatal-warnings // object Test { - (Vector(): Seq[_]) match { case List() => true; case Nil => false } + (Vector(): Seq[_]) match { case List() => true; case Nil => false; case x => throw new MatchError(x) } } diff --git a/test/files/pos/t6022.scala b/test/files/pos/t6022.scala index e521007a48..8a1a8581af 100644 --- a/test/files/pos/t6022.scala +++ b/test/files/pos/t6022.scala @@ -5,5 +5,6 @@ class Test { case x: AnyRef if false => case list: Option[_] => case product: Product => // change Product to String and it's all good + case x => throw new MatchError(x) } } diff --git a/test/files/presentation/doc/doc.scala b/test/files/presentation/doc/doc.scala index cdc37d0020..1fa782c827 100644 --- a/test/files/presentation/doc/doc.scala +++ b/test/files/presentation/doc/doc.scala @@ -130,6 +130,7 @@ object Test extends InteractiveTest { case s: Seq[_] => s exists (existsText(_, text)) case p: Product => p.productIterator exists (existsText(_, text)) case c: Comment => existsText(c.body, text) + case x => throw new MatchError(x) } val (derived, base) = compiler.ask { () => val derived = compiler.rootMirror.RootPackage.info.decl(newTermName("p")).info.decl(newTypeName("Derived")) diff --git a/test/files/run/Course-2002-07.scala b/test/files/run/Course-2002-07.scala index b9ea570e26..5a43d2f909 100644 --- a/test/files/run/Course-2002-07.scala +++ b/test/files/run/Course-2002-07.scala @@ -94,7 +94,7 @@ object M1 { object M2 { - trait Expr; + sealed trait Expr; case class Number(n: Int) extends Expr; case class Sum(e1: Expr, e2: Expr) extends Expr; @@ -118,7 +118,7 @@ object M2 { object M3 { - trait Expr { + sealed trait Expr { def eval: Int = this match { case Number(n) => n case Sum(e1, e2) => e1.eval + e2.eval @@ -338,7 +338,7 @@ object M8 { object M9 { - trait Expr { + sealed trait Expr { def derive(v: Var): Expr = this match { case Number(_) => Number(0) case Var(name) => if (name == v.name) Number(1) else Number(0) @@ -379,7 +379,7 @@ object MA { case (k1,v1) :: xs1 => if (k1 == k) v1 else lookup(xs1, k) } - trait Expr { + sealed trait Expr { def + (that: Expr) = Sum(this, that); def * (that: Expr) = Prod(this, that); def derive(v: Var): Expr = this match { diff --git a/test/files/run/caseclasses.scala b/test/files/run/caseclasses.scala index 10c0916dc0..fd482ecef8 100644 --- a/test/files/run/caseclasses.scala +++ b/test/files/run/caseclasses.scala @@ -27,6 +27,7 @@ object Test extends App { (f(2): AnyRef) match { case Foo(1) => Console.println("OK") case Bar() => Console.println("NO") + case x => throw new MatchError(x) } try { Bar() productElement 3 diff --git a/test/files/run/existentials.scala b/test/files/run/existentials.scala index bdd6fb93ee..5cc4eee64a 100644 --- a/test/files/run/existentials.scala +++ b/test/files/run/existentials.scala @@ -4,7 +4,7 @@ import scala.language.reflectiveCalls class Foo { class Line { case class Cell[T](var x: T) - def f[T](x: Any): Cell[t1] forSome { type t1 } = x match { case y: Cell[t] => y } + def f[T](x: Any): Cell[t1] forSome { type t1 } = (x: @unchecked) match { case y: Cell[t] => y } var x: Cell[T] forSome { type T } = new Cell(1) println({ x = new Cell("abc"); x }) @@ -14,7 +14,7 @@ class Foo { class FooW { class Line { case class Cell[T](var x: T) - def f[T](x: Any): Cell[ _ ] = x match { case y: Cell[t] => y } + def f[T](x: Any): Cell[ _ ] = (x: @unchecked) match { case y: Cell[t] => y } var x: Cell[_] = new Cell(1) println({ x = new Cell("abc"); x }) @@ -41,7 +41,7 @@ object LUB { object Bug1189 { case class Cell[T](x: T) type U = Cell[T1] forSome { type T1 } - def f(x: Any): U = x match { case y: Cell[_] => y } + def f(x: Any): U = (x: @unchecked) match { case y: Cell[_] => y } var x: U = Cell(1) println(x) diff --git a/test/files/run/gadts.scala b/test/files/run/gadts.scala index 57c7fc8af0..d3ac0b17dd 100644 --- a/test/files/run/gadts.scala +++ b/test/files/run/gadts.scala @@ -1,4 +1,4 @@ -abstract class Term[T] +sealed abstract class Term[T] case class Lit(x: Int) extends Term[Int] case class Succ(t: Term[Int]) extends Term[Int] case class IsZero(t: Term[Int]) extends Term[Boolean] diff --git a/test/files/run/macro-bundle-whitebox-use-raw/Test_2.scala b/test/files/run/macro-bundle-whitebox-use-raw/Test_2.scala index 995da737cc..4b15dc4965 100644 --- a/test/files/run/macro-bundle-whitebox-use-raw/Test_2.scala +++ b/test/files/run/macro-bundle-whitebox-use-raw/Test_2.scala @@ -15,5 +15,6 @@ object Test extends App { 42 match { case ExtractorMacro(x) => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/macro-bundle-whitebox-use-refined/Test_2.scala b/test/files/run/macro-bundle-whitebox-use-refined/Test_2.scala index 995da737cc..4b15dc4965 100644 --- a/test/files/run/macro-bundle-whitebox-use-refined/Test_2.scala +++ b/test/files/run/macro-bundle-whitebox-use-refined/Test_2.scala @@ -15,5 +15,6 @@ object Test extends App { 42 match { case ExtractorMacro(x) => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/macro-rangepos-subpatterns/Test_2.scala b/test/files/run/macro-rangepos-subpatterns/Test_2.scala index df152c4d2b..b2559e34ed 100644 --- a/test/files/run/macro-rangepos-subpatterns/Test_2.scala +++ b/test/files/run/macro-rangepos-subpatterns/Test_2.scala @@ -2,5 +2,6 @@ object Test extends App { 42 match { case Extractor(a) => println(a) + case x => throw new MatchError(x) } } diff --git a/test/files/run/macro-subpatterns/Test_2.scala b/test/files/run/macro-subpatterns/Test_2.scala index dc6e668877..adc1653deb 100644 --- a/test/files/run/macro-subpatterns/Test_2.scala +++ b/test/files/run/macro-subpatterns/Test_2.scala @@ -1,5 +1,6 @@ object Test extends App { 42 match { case Extractor(a @ Extractor(b @ Extractor(c))) => println(a); println(b); println(c) + case x => throw new MatchError(x) } } diff --git a/test/files/run/macro-vampire-false-warning/Macros_1.scala b/test/files/run/macro-vampire-false-warning/Macros_1.scala index 9ca5bd42ac..48230f9e47 100644 --- a/test/files/run/macro-vampire-false-warning/Macros_1.scala +++ b/test/files/run/macro-vampire-false-warning/Macros_1.scala @@ -19,7 +19,7 @@ object Macros { import c.universe._ import Flag._ // val kvps = xs.toList map { case q"${_}(${Literal(Constant(name: String))}).->[${_}]($value)" => name -> value } - val kvps = xs.map(_.tree).toList map { case Apply(TypeApply(Select(Apply(_, List(Literal(Constant(name: String)))), _), _), List(value)) => name -> value } + val kvps = xs.map(_.tree).toList map { case Apply(TypeApply(Select(Apply(_, List(Literal(Constant(name: String)))), _), _), List(value)) => name -> value case x => throw new MatchError(x) } // val fields = kvps map { case (k, v) => q"@body($v) def ${TermName(k)} = macro Macros.selFieldImpl" } val fields = kvps map { case (k, v) => DefDef( Modifiers(MACRO, typeNames.EMPTY, List(Apply(Select(New(Ident(TypeName("body"))), termNames.CONSTRUCTOR), List(v)))), diff --git a/test/files/run/macro-whitebox-extractor/Test_2.scala b/test/files/run/macro-whitebox-extractor/Test_2.scala index 41be6f9767..c0b95e0703 100644 --- a/test/files/run/macro-whitebox-extractor/Test_2.scala +++ b/test/files/run/macro-whitebox-extractor/Test_2.scala @@ -1,5 +1,6 @@ object Test extends App { 42 match { case Extractor(x) => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/manifests-new.scala b/test/files/run/manifests-new.scala index 87ff417404..502c2d1bdd 100644 --- a/test/files/run/manifests-new.scala +++ b/test/files/run/manifests-new.scala @@ -39,6 +39,7 @@ object Test case CO => showsCovariance && !showsContravariance && !showsInvariance case IN => showsInvariance && !showsCovariance && !showsContravariance case CONTRA => showsContravariance && !showsCovariance && !showsInvariance + case x => throw new MatchError(x) } } diff --git a/test/files/run/manifests-old.scala b/test/files/run/manifests-old.scala index cd91b25d04..4aa6e97dac 100644 --- a/test/files/run/manifests-old.scala +++ b/test/files/run/manifests-old.scala @@ -37,6 +37,7 @@ object Test case CO => showsCovariance && !showsContravariance && !showsInvariance case IN => showsInvariance && !showsCovariance && !showsContravariance case CONTRA => showsContravariance && !showsCovariance && !showsInvariance + case x => throw new MatchError(x) } } diff --git a/test/files/run/matchemptyarray.scala b/test/files/run/matchemptyarray.scala index 42b022c713..a6d4538763 100644 --- a/test/files/run/matchemptyarray.scala +++ b/test/files/run/matchemptyarray.scala @@ -3,5 +3,6 @@ import scala.tools.partest.Util.ArrayDeep object Test extends App{ Array[String]() match { case x@Array() => println(x.deep.toString()); + case x => throw new MatchError(x) } } diff --git a/test/files/run/matchonstream.check b/test/files/run/matchonstream.check index 7a44e93b26..6e42636ea2 100644 --- a/test/files/run/matchonstream.check +++ b/test/files/run/matchonstream.check @@ -1 +1,4 @@ +matchonstream.scala:2: warning: match may not be exhaustive. + LazyList.from(1) match { case LazyList(1, 2, x @_*) => println(s"It worked! (class: ${x.getClass.getSimpleName})") } + ^ It worked! (class: LazyList) diff --git a/test/files/run/patmat-behavior.check b/test/files/run/patmat-behavior.check index 7cc2130783..01e662ac11 100644 --- a/test/files/run/patmat-behavior.check +++ b/test/files/run/patmat-behavior.check @@ -88,6 +88,30 @@ patmat-behavior.scala:87: warning: fruitless type test: a value of type s.C21[A] patmat-behavior.scala:87: warning: fruitless type test: a value of type s.C21[A] cannot also be a s.C11[A] def gd6[A](x: C21[A]) = x match { case G00() => ??? ; case G10(x) => x ; case G20(x, y) => x ; case G01(xs @ _*) => xs.head ; case G11(x, ys @ _*) => x ; case G21(x, y, zs @ _*) => x } ^ +patmat-behavior.scala:36: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga1(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ +patmat-behavior.scala:37: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga2(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ +patmat-behavior.scala:38: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga3(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ +patmat-behavior.scala:39: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga4(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ +patmat-behavior.scala:40: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga5(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ +patmat-behavior.scala:41: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in (s.C00[?], s.C01[?], s.C10[?], s.C11[?], s.C20[?], s.C21[?])), ??, C01(_), C11(_, _), C21(_, _, _) + def ga6(x: Any) = x match { case C00() => 1 ; case C10(x) => 2 ; case C20(x, y) => 3 ; case C01(xs) => 4 ; case C11(x, ys) => 5 ; case C21(x, y, zs) => 6 } + ^ patmat-behavior.scala:43: warning: match may not be exhaustive. It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _) def gb1[A](x: C[A]) = x match { case E00() => ??? ; case E10(x) => x ; case E20(x, y) => x ; case E01(xs @ _*) => xs.head ; case E11(x, ys @ _*) => x ; case E21(x, y, zs @ _*) => x } @@ -136,6 +160,24 @@ patmat-behavior.scala:55: warning: match may not be exhaustive. It would fail on the following inputs: C00(), C01(_), C10(_), C11(_, _), C20(_, _), C21(_, _, _) def gc6[A](x: C[A]) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } ^ +patmat-behavior.scala:57: warning: match may not be exhaustive. + def gd1[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ +patmat-behavior.scala:58: warning: match may not be exhaustive. + def gd2[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ +patmat-behavior.scala:59: warning: match may not be exhaustive. + def gd3[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ +patmat-behavior.scala:60: warning: match may not be exhaustive. + def gd4[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ +patmat-behavior.scala:61: warning: match may not be exhaustive. + def gd5[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ +patmat-behavior.scala:62: warning: match may not be exhaustive. + def gd6[A, B <: C[A]](x: B) = x match { case F00() => ??? ; case F10(x) => x ; case F20(x, y) => x ; case F01(xs @ _*) => xs.head ; case F11(x, ys @ _*) => x ; case F21(x, y, zs @ _*) => x } + ^ patmat-behavior.scala:68: warning: match may not be exhaustive. It would fail on the following input: C00() def gb1[A](x: C00[A]) = x match { case E00() => ??? ; case E10(x) => x ; case E20(x, y) => x ; case E01(xs @ _*) => xs.head ; case E11(x, ys @ _*) => x ; case E21(x, y, zs @ _*) => x } diff --git a/test/files/run/patmatnew.check b/test/files/run/patmatnew.check index e277591383..da5143a3f1 100644 --- a/test/files/run/patmatnew.check +++ b/test/files/run/patmatnew.check @@ -16,6 +16,22 @@ patmatnew.scala:356: warning: multiline expressions might require enclosing pare patmatnew.scala:356: warning: a pure expression does nothing in statement position case 3 => assert(false); "KO" ^ +patmatnew.scala:119: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in Test.Test717.foo1.Bar), Bar((x: Int forSome x not in 2)) + val res = (foo1.Bar(2): Any) match { + ^ +patmatnew.scala:138: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Shmeez.this.Tree forSome x not in (HagbardCeline, Shmeez.this.Beez)), Beez((x: Int forSome x not in 2)) + def foo = tree match { + ^ +patmatnew.scala:148: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Test.TestGuards.Tree forSome x not in Test.TestGuards.Beez), Beez(_) + val res = tree match { + ^ +patmatnew.scala:153: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Test.TestGuards.Tree forSome x not in Test.TestGuards.Beez), Beez(_) + val ret = (Beez(3): Tree) match { + ^ patmatnew.scala:175: warning: match may not be exhaustive. It would fail on the following inputs: List(_), Nil def doMatch(xs: List[String]): String = xs match { @@ -24,6 +40,13 @@ patmatnew.scala:178: warning: match may not be exhaustive. It would fail on the following inputs: List(_), Nil def doMatch2(xs: List[String]): List[String] = xs match { ^ +patmatnew.scala:193: warning: match may not be exhaustive. + def doMatch(l: Seq[String]): String = l match { + ^ +patmatnew.scala:264: warning: match may not be exhaustive. +It would fail on the following inputs: (x: Any forSome x not in Test.TestSequence06.A), A((x: Any forSome x not in (1, Test.TestSequence06.A))), A(A((x: Any forSome x not in 1))) + def doMatch(x: Any, bla: Int) = x match { + ^ patmatnew.scala:280: warning: match may not be exhaustive. It would fail on the following inputs: List(_), Nil def doMatch1(xs: List[Char]) = xs match { @@ -32,6 +55,22 @@ patmatnew.scala:283: warning: match may not be exhaustive. It would fail on the following inputs: List(_), Nil def doMatch2(xs: List[Char]) = xs match { ^ +patmatnew.scala:286: warning: match may not be exhaustive. + def doMatch3(xs: Seq[Char]) = xs match { + ^ +patmatnew.scala:290: warning: match may not be exhaustive. + def doMatch4(xs: Seq[Char]) = xs match { + ^ +patmatnew.scala:318: warning: match may not be exhaustive. + lazyList match { + ^ +patmatnew.scala:396: warning: match may not be exhaustive. + "baz" match { + ^ +patmatnew.scala:443: warning: match may not be exhaustive. +It would fail on the following input: (x: 42 forSome x not in FooBar) + def lala() = 42 match { + ^ patmatnew.scala:492: warning: unreachable code case _ if false => ^ diff --git a/test/files/run/pure-warning-post-macro/Macro_1.scala b/test/files/run/pure-warning-post-macro/Macro_1.scala index 21d8972dee..a21569107e 100644 --- a/test/files/run/pure-warning-post-macro/Macro_1.scala +++ b/test/files/run/pure-warning-post-macro/Macro_1.scala @@ -8,6 +8,7 @@ object Macro { block match { case Block(stats, expr) => q"_root_.scala.List.apply[${weakTypeOf[T]}](..${stats :+ expr})" + case x => throw new MatchError(x) } } } diff --git a/test/files/run/reflection-valueclasses-magic.scala b/test/files/run/reflection-valueclasses-magic.scala index 9034922b6f..bc461f6293 100644 --- a/test/files/run/reflection-valueclasses-magic.scala +++ b/test/files/run/reflection-valueclasses-magic.scala @@ -16,6 +16,7 @@ object Test extends App { sym match { // initialize parameter symbols case meth: MethodSymbol => meth.paramLists.flatten.map(_.info) + case _ => throw new MatchError(sym) } s"$sym: ${sym.info}" } diff --git a/test/files/run/sd187.check b/test/files/run/sd187.check index 3dc27be113..c8fcab5823 100644 --- a/test/files/run/sd187.check +++ b/test/files/run/sd187.check @@ -5,18 +5,18 @@ [2302][2302][2302]C.super.(); [9]() }; - [103:904]def commonSubPattern([124:130]x: [127:130]): [107]AnyVal = [205:206]{ - [205:206] var rc6: [205]Boolean = [205]false; - [205:206] var x3: [205]String = [205][205][205]null.asInstanceOf[[205]String]; - [205:206]{ - [205:206]case val x1: [205]Any = [205:206]x; - [205:206]case8(){ + [103:904]def commonSubPattern([124:130]x: [127:130]): [107]AnyVal = [206:220]{ + [206:220] var rc6: [211]Boolean = [211]false; + [206:220] var x3: [211]String = [211][211][211]null.asInstanceOf[[211]String]; + [206:220]{ + [206:220]case val x1: [211]Any = [206:220]([206:207]x: [211]); + [206:220]case8(){ [312:324]if ([313][313]x1.isInstanceOf[[313]Option[_]]) [325:327][325]matchEnd7([325:327]()) else [313][313]case9() }; - [205:206]case9(){ + [206:220]case9(){ [412:421]if ([412][412]x1.isInstanceOf[[412]String]) [412]{ [412][412]rc6 = [412]true; @@ -29,23 +29,23 @@ else [412][412]case10() }; - [205:206]case10(){ + [206:220]case10(){ [612:621]if ([612][612]rc6.&&([627][627]x3.==([630]"6"))) [712][712]matchEnd7([712][712]x3.hashCode()) else [612][612]case11() }; - [205:206]case11(){ - [205:206][205:206]matchEnd7([205:206]throw [205:206][205:206][205:206]new [205:206]MatchError([205:206]x1)) + [206:220]case11(){ + [206:220][206:220]matchEnd7([206:220]throw [206:220][206:220][206:220]new [206:220]MatchError([206:220]x1)) }; - [205:206]matchEnd7(x: [NoPosition]AnyVal){ - [205:206]x + [206:220]matchEnd7(x: [NoPosition]AnyVal){ + [206:220]x } } }; - [1003:1306]def extractor([1017:1023]x: [1020:1023]): [1007]Any = [1027:1028]{ - [1027:1028]case val x1: [1027]Any = [1027:1028]x; - [1027:1028]case6(){ + [1003:1306]def extractor([1017:1023]x: [1020:1023]): [1007]Any = [1028:1041]{ + [1028:1041]case val x1: [1032]Any = [1028:1041]([1028:1029]x: [1032]); + [1028:1041]case6(){ [1112:1126]if ([1120][1120]x1.isInstanceOf[[1120]Product2[T1,T2]]) [1112:1126]{ [1112:1126] val x2: [1120]Product2[T1,T2] = [1120]([1120][1120]x1.asInstanceOf[[1120]Product2[T1,T2]]: [1120]Product2[T1,T2]); @@ -63,11 +63,11 @@ else [1120][1120]case7() }; - [1027:1028]case7(){ - [1027:1028][1027:1028]matchEnd5([1027:1028]throw [1027:1028][1027:1028][1027:1028]new [1027:1028]MatchError([1027:1028]x1)) + [1028:1041]case7(){ + [1028:1041][1028:1041]matchEnd5([1028:1041]throw [1028:1041][1028:1041][1028:1041]new [1028:1041]MatchError([1028:1041]x1)) }; - [1027:1028]matchEnd5(x: [NoPosition]Any){ - [1027:1028]x + [1028:1041]matchEnd5(x: [NoPosition]Any){ + [1028:1041]x } }; [1403:2204]def swatch: [1407]String = [1505:2106]try { diff --git a/test/files/run/sd187.scala b/test/files/run/sd187.scala index 241cd0ad34..d8892be7f1 100644 --- a/test/files/run/sd187.scala +++ b/test/files/run/sd187.scala @@ -8,7 +8,7 @@ object Test extends DirectTest { """ |class C { // | def commonSubPattern(x: Any) = { // - | x match { // + | (x: @unchecked) match { // | case _: Option[_] => // | case s: String if s == "4" => // | s.hashCode // @@ -16,7 +16,7 @@ object Test extends DirectTest { | s.hashCode // | } // | } // - | def extractor(x: Any) = x match { // + | def extractor(x: Any) = (x: @unchecked) match { // | case Product2(a, b) => // | a // | } // diff --git a/test/files/run/string-switch.scala b/test/files/run/string-switch.scala index 95cd1c9fd8..6a1522b416 100644 --- a/test/files/run/string-switch.scala +++ b/test/files/run/string-switch.scala @@ -28,6 +28,7 @@ object Test extends App { def unitary(in: String) = (in : @switch) match { case "A" => + case x => throw new MatchError(x) } List("A","X").foreach { s => println(s"$s ${Try(unitary(s))}") @@ -65,4 +66,4 @@ object Test extends App { List("Ea", "FB", "cC", "xx", null).foreach { s => println(s"$s ${s.##} ${Try(onceOnly(Iterator(s)))}") } -} \ No newline at end of file +} diff --git a/test/files/run/t10067/Test.scala b/test/files/run/t10067/Test.scala index af1e12592e..8e02bf32d1 100644 --- a/test/files/run/t10067/Test.scala +++ b/test/files/run/t10067/Test.scala @@ -14,6 +14,7 @@ object Test { //this will fail with java.lang.NoSuchMethodError icObj match { case ic: ocStable.InnerClass => ; + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t1434.scala b/test/files/run/t1434.scala index b55748193c..6860f8acd5 100644 --- a/test/files/run/t1434.scala +++ b/test/files/run/t1434.scala @@ -7,6 +7,7 @@ object Test { case a: A[_] if(a.op != null) => "with op" case c: C => "C" case b: B => "B" + case x => throw new MatchError(x) } def main(args: Array[String]) = { diff --git a/test/files/run/t1503.scala b/test/files/run/t1503.scala index 20c4acff0d..5c84d57026 100644 --- a/test/files/run/t1503.scala +++ b/test/files/run/t1503.scala @@ -4,10 +4,10 @@ object Whatever { object Test extends App { // this should make it abundantly clear Any is the best return type we can guarantee - def matchWhatever(x: Any): Any = x match { case n @ Whatever => n } + def matchWhatever(x: Any): Any = (x: @unchecked) match { case n @ Whatever => n } // until 2.13 the return type used to be Whatever.type // now it is Any - def matchWhateverCCE(x: Any) = x match { case n @ Whatever => n } + def matchWhateverCCE(x: Any) = (x: @unchecked) match { case n @ Whatever => n } // just to exercise it a bit assert(matchWhatever(1) == 1) diff --git a/test/files/run/t2577.scala b/test/files/run/t2577.scala index 6d836a3996..6bacad9854 100644 --- a/test/files/run/t2577.scala +++ b/test/files/run/t2577.scala @@ -11,6 +11,7 @@ object Test { def main(args: Array[String]): Unit = { val targ = typeOf[x.type].widen match { case TypeRef(_, _, arg :: _) => arg + case x => throw new MatchError(x) } println(targ) } diff --git a/test/files/run/t3050.scala b/test/files/run/t3050.scala index 160f8b664b..af6cc18ca1 100644 --- a/test/files/run/t3050.scala +++ b/test/files/run/t3050.scala @@ -1,7 +1,7 @@ object Test { def main(args: Array[String]): Unit = { val x = - try { ("": Any) match { case List(_*) => true } } + try { ("": Any) match { case List(_*) => true case x => throw new MatchError(x) } } catch { case _: Throwable => false } assert(!x) diff --git a/test/files/run/t3150.scala b/test/files/run/t3150.scala index 034703b5f7..38e19b7384 100644 --- a/test/files/run/t3150.scala +++ b/test/files/run/t3150.scala @@ -1,6 +1,6 @@ object Test { case object Bob { override def equals(other: Any) = true } - def f(x: Any) = x match { case Bob => Bob } + def f(x: Any) = x match { case Bob => Bob case x => throw new MatchError(x) } def main(args: Array[String]): Unit = { assert(f(Bob) eq Bob) diff --git a/test/files/run/t3395.scala b/test/files/run/t3395.scala index eea9bb9192..9489b67171 100644 --- a/test/files/run/t3395.scala +++ b/test/files/run/t3395.scala @@ -3,11 +3,13 @@ object Test { Seq("") match { case Seq("") => println("abc") case Seq(_, _, x) => println(x) + case x => throw new MatchError(x) } Seq[Any](1, 2, "def") match { case Seq("") => println("abc") case Seq(_, _, x) => println(x) + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t3702.scala b/test/files/run/t3702.scala index 0cdafd90b6..cde65ecf2f 100644 --- a/test/files/run/t3702.scala +++ b/test/files/run/t3702.scala @@ -2,6 +2,7 @@ object Test { def foo(h: Any, t: List[Any]) = h match { case 5 :: _ => () case List(from) => from + case x => throw new MatchError(x) } def main(args: Array[String]): Unit = { diff --git a/test/files/run/t3888.check b/test/files/run/t3888.check deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/files/run/t4025.check b/test/files/run/t4025.check index 697070e924..688f4becbd 100644 --- a/test/files/run/t4025.check +++ b/test/files/run/t4025.check @@ -9,7 +9,7 @@ class Red scala> -scala> def f(c: Any) = c match { case Red(_) => () } +scala> def f(c: Any) = (c: @unchecked) match { case Red(_) => () } def f(c: Any): Unit scala> :quit diff --git a/test/files/run/t4025.scala b/test/files/run/t4025.scala index 5db0093970..5066411f52 100644 --- a/test/files/run/t4025.scala +++ b/test/files/run/t4025.scala @@ -7,6 +7,6 @@ class Color(val red: Int) case class Red(r:Int) extends Color(r) -def f(c: Any) = c match { case Red(_) => () } +def f(c: Any) = (c: @unchecked) match { case Red(_) => () } """ } diff --git a/test/files/run/t4415.scala b/test/files/run/t4415.scala index 33d3908693..5892b0c16d 100644 --- a/test/files/run/t4415.scala +++ b/test/files/run/t4415.scala @@ -26,6 +26,7 @@ object Test { case SubclassMatch(p) => p case StandardMatch(p) => p + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t4482.scala b/test/files/run/t4482.scala index 392861c22e..6293d81434 100644 --- a/test/files/run/t4482.scala +++ b/test/files/run/t4482.scala @@ -4,7 +4,7 @@ trait Bar case class Spam(i: Int) extends Foo with Bar object Test { - def matchParent(p:Any) = p match { + def matchParent(p:Any) = (p: @unchecked) match { case f:Foo if f.i == 1 => 1 case _:Bar => 2 case _:Foo => 3 diff --git a/test/files/run/t4897.scala b/test/files/run/t4897.scala index f65c2745ef..d358ca7ea6 100644 --- a/test/files/run/t4897.scala +++ b/test/files/run/t4897.scala @@ -2,7 +2,7 @@ class CSuper { object A } class C extends CSuper { - def f = (A: AnyRef) match { case _: A.type => "joepie" } + def f = (A: AnyRef @unchecked) match { case _: A.type => "joepie" } } object Test extends C with App { diff --git a/test/files/run/t5612.scala b/test/files/run/t5612.scala index 950f38fb0d..8858d4c811 100644 --- a/test/files/run/t5612.scala +++ b/test/files/run/t5612.scala @@ -12,6 +12,7 @@ class Foo { case L.One => println("ONE"); return case L.Two => println("TWO") case L.Three => println("THREE"); break() + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t5688.scala b/test/files/run/t5688.scala index 266d364ae4..dc2ffc64a5 100644 --- a/test/files/run/t5688.scala +++ b/test/files/run/t5688.scala @@ -1,5 +1,5 @@ object Test extends App { - trait T + sealed trait T trait TA trait TB diff --git a/test/files/run/t5704.scala b/test/files/run/t5704.scala index d91e995151..6297fa97ba 100644 --- a/test/files/run/t5704.scala +++ b/test/files/run/t5704.scala @@ -13,6 +13,7 @@ object Test extends App { toolbox.typecheck(tree) match{ case Apply(Select(lhs,op),rhs::Nil) => println(rhs.tpe) + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t576.scala b/test/files/run/t576.scala index 3cee8c5cd9..bf133d6b25 100644 --- a/test/files/run/t576.scala +++ b/test/files/run/t576.scala @@ -30,6 +30,7 @@ object Test { case _: x3.type => 3 case _: self.type => 4 case x: Dingus.type => x.IamDingus + case x => throw new MatchError(x) } } diff --git a/test/files/run/t5830.scala b/test/files/run/t5830.scala index 95dd41cd25..296651f439 100644 --- a/test/files/run/t5830.scala +++ b/test/files/run/t5830.scala @@ -3,7 +3,7 @@ import scala.annotation.switch object Test extends App { - def noSwitch(ch: Char, eof: Boolean) = ch match { + def noSwitch(ch: Char, eof: Boolean) = (ch: @unchecked) match { case 'a' if eof => println("a with oef") // then branch } diff --git a/test/files/run/t5903b/Test_2.scala b/test/files/run/t5903b/Test_2.scala index 0f6f80d327..4a0cc3dd82 100644 --- a/test/files/run/t5903b/Test_2.scala +++ b/test/files/run/t5903b/Test_2.scala @@ -2,5 +2,6 @@ object Test extends App { import Interpolation._ 2 match { case t"$x" => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/t5903c/Test_2.scala b/test/files/run/t5903c/Test_2.scala index 90ef19b94a..5a1e7c54e7 100644 --- a/test/files/run/t5903c/Test_2.scala +++ b/test/files/run/t5903c/Test_2.scala @@ -3,5 +3,6 @@ object Test extends App { import Interpolation._ 2 match { case t"$x" => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/t5903d/Test_2.scala b/test/files/run/t5903d/Test_2.scala index 653b3e85d9..1871197c16 100644 --- a/test/files/run/t5903d/Test_2.scala +++ b/test/files/run/t5903d/Test_2.scala @@ -3,5 +3,6 @@ object Test extends App { import Interpolation._ 42 match { case t"$x" => println(x) + case x => throw new MatchError(x) } } diff --git a/test/files/run/t5914.scala b/test/files/run/t5914.scala index 39a8dd3caa..21456c8754 100644 --- a/test/files/run/t5914.scala +++ b/test/files/run/t5914.scala @@ -12,6 +12,7 @@ trait Trees { tree match { case TypeTree(_) => println("lolwut") case null => println("correct") + case x => throw new MatchError(x) } } diff --git a/test/files/run/t6011b.scala b/test/files/run/t6011b.scala index 9d15bd664c..83fa581507 100644 --- a/test/files/run/t6011b.scala +++ b/test/files/run/t6011b.scala @@ -2,7 +2,7 @@ object Test extends App { var cond = true // should not generate a switch - def f(ch: Char): Int = ch match { + def f(ch: Char): Int = (ch: @unchecked) match { case 'a' if cond => 1 case 'z' | 'a' => 2 } diff --git a/test/files/run/t6077_patmat_cse_irrefutable.scala b/test/files/run/t6077_patmat_cse_irrefutable.scala index 18db6c13ef..cbbe999970 100644 --- a/test/files/run/t6077_patmat_cse_irrefutable.scala +++ b/test/files/run/t6077_patmat_cse_irrefutable.scala @@ -1,3 +1,4 @@ +// scalac: -Xno-unsealed-patmat-analysis class LiteralNode(val value: Any) object LiteralNode { diff --git a/test/files/run/t6104.scala b/test/files/run/t6104.scala index ac6d4c77e5..e2b543a084 100644 --- a/test/files/run/t6104.scala +++ b/test/files/run/t6104.scala @@ -2,6 +2,7 @@ class A { Self => val ok = "ok" this match { case me@Self => println(me.ok) + case x => throw new MatchError(x) } } diff --git a/test/files/run/t6111.scala b/test/files/run/t6111.scala index 5dec2d898b..6d552e34fb 100644 --- a/test/files/run/t6111.scala +++ b/test/files/run/t6111.scala @@ -6,6 +6,7 @@ object Foo { def unapply[S, T](scrutinee: S)(implicit witness: FooHasType[S, T]): Option[T] = scrutinee match { case i: Int => Some((i, i).asInstanceOf[T]) + case x => throw new MatchError(x) } } @@ -21,8 +22,9 @@ object Test extends App { val x = 8 println(x match { case Foo(p) => p // p should be a pair of Int + case x => throw new MatchError(x) }) // Prints '(x, x)' - "x" match { case Foo997(a) => println(a) } + "x" match { case Foo997(a) => println(a) case x => throw new MatchError(x) } } diff --git a/test/files/run/t6288.check b/test/files/run/t6288.check index ca377e92af..eb431f85e1 100644 --- a/test/files/run/t6288.check +++ b/test/files/run/t6288.check @@ -1,8 +1,11 @@ +newSource1.scala:28: warning: match may not be exhaustive. + 0 match { + ^ [[syntax trees at end of patmat]] // newSource1.scala -[0:417]package [0:0] { - [0:105]object Case3 extends [13:105][106]scala.AnyRef { - [106]def (): [13]Case3.type = [106]{ - [106][106][106]Case3.super.(); +[0:553]package [0:0] { + [0:151]object Case3 extends [13:151][152]scala.AnyRef { + [152]def (): [13]Case3.type = [152]{ + [152][152][152]Case3.super.(); [13]() }; [17:60]def unapply([29:35]z: [32:35]): [21]Option[Int] = [52:60][52:56][52:56]new [52:56]Some[Int]([57:59]-1); @@ -21,89 +24,89 @@ [89][89]case6() }; [64:66]case6(){ - [64:66][64:66]matchEnd4([64:66]throw [64:66][64:66][64:66]new [64:66]MatchError([64:66]"")) + [122:145][122]matchEnd4([122]throw [128][128][128]new [132]scala.MatchError([143]x1)) }; [64:66]matchEnd4(x: [NoPosition]Unit){ [64:66]x } } }; - [106:216]object Case4 extends [119:216][217]scala.AnyRef { - [217]def (): [119]Case4.type = [217]{ - [217][217][217]Case4.super.(); - [119]() + [152:308]object Case4 extends [165:308][309]scala.AnyRef { + [309]def (): [165]Case4.type = [309]{ + [309][309][309]Case4.super.(); + [165]() }; - [123:171]def unapplySeq([138:144]z: [141:144]): [127]Option[List[Int]] = [167:171]scala.None; - [175:177]{ - [175:177]case val x1: [175]String("") = [175:177]""; - [175:177]case5(){ - [195:204]if ([200][200][200]"".ne([200]null)) - [195:200]{ - [195:200] val o7: [195]Option[List[Int]] = [195:200][195:200]Case4.unapplySeq([195]x1); - [208:210]if ([195][195]o7.isEmpty.unary_!.&&([195][195][195][195]o7.get.!=([195]null).&&([195][195][195][195]o7.get.lengthCompare([195]1).==([195]0)))) - [208:210][208]matchEnd4([208:210]()) + [169:217]def unapplySeq([184:190]z: [187:190]): [173]Option[List[Int]] = [213:217]scala.None; + [221:223]{ + [221:223]case val x1: [221]String("") = [221:223]""; + [221:223]case5(){ + [241:250]if ([246][246][246]"".ne([246]null)) + [241:246]{ + [241:246] val o7: [241]Option[List[Int]] = [241:246][241:246]Case4.unapplySeq([241]x1); + [254:256]if ([241][241]o7.isEmpty.unary_!.&&([241][241][241][241]o7.get.!=([241]null).&&([241][241][241][241]o7.get.lengthCompare([241]1).==([241]0)))) + [254:256][254]matchEnd4([254:256]()) else - [195][195]case6() + [241][241]case6() } else - [200][200]case6() + [246][246]case6() }; - [175:177]case6(){ - [175:177][175:177]matchEnd4([175:177]throw [175:177][175:177][175:177]new [175:177]MatchError([175:177]"")) + [221:223]case6(){ + [279:302][279]matchEnd4([279]throw [285][285][285]new [289]scala.MatchError([300]x1)) }; - [175:177]matchEnd4(x: [NoPosition]Unit){ - [175:177]x + [221:223]matchEnd4(x: [NoPosition]Unit){ + [221:223]x } } }; - [217:312]object Case5 extends [230:312][313]scala.AnyRef { - [313]def (): [230]Case5.type = [313]{ - [313][313][313]Case5.super.(); - [230]() + [309:448]object Case5 extends [322:448][449]scala.AnyRef { + [449]def (): [322]Case5.type = [449]{ + [449][449][449]Case5.super.(); + [322]() }; - [234:269]def unapply([246:252]z: [249:252]): [238]Boolean = [265:269]true; - [273:275]{ - [273:275]case val x1: [273]String("") = [273:275]""; - [273:275]case5(){ - [293:300]if ([298][298][298]"".ne([298]null)) - [293:298]{ - [293:298] val o7: [293]Option[List[Int]] = [293:298][293:298]Case4.unapplySeq([293]x1); - [304:306]if ([293][293]o7.isEmpty.unary_!.&&([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([293]0)))) - [304:306][304]matchEnd4([304:306]()) + [326:361]def unapply([338:344]z: [341:344]): [330]Boolean = [357:361]true; + [365:367]{ + [365:367]case val x1: [365]String("") = [365:367]""; + [365:367]case5(){ + [385:392]if ([390][390][390]"".ne([390]null)) + [385:390]{ + [385:390] val o7: [385]Option[List[Int]] = [385:390][385:390]Case4.unapplySeq([385]x1); + [396:398]if ([385][385]o7.isEmpty.unary_!.&&([385][385][385][385]o7.get.!=([385]null).&&([385][385][385][385]o7.get.lengthCompare([385]0).==([385]0)))) + [396:398][396]matchEnd4([396:398]()) else - [293][293]case6() + [385][385]case6() } else - [298][298]case6() + [390][390]case6() }; - [273:275]case6(){ - [273:275][273:275]matchEnd4([273:275]throw [273:275][273:275][273:275]new [273:275]MatchError([273:275]"")) + [365:367]case6(){ + [419:442][419]matchEnd4([419]throw [425][425][425]new [429]scala.MatchError([440]x1)) }; - [273:275]matchEnd4(x: [NoPosition]Unit){ - [273:275]x + [365:367]matchEnd4(x: [NoPosition]Unit){ + [365:367]x } } }; - [313:417]object Case6 extends [326:417][417]scala.AnyRef { - [417]def (): [326]Case6.type = [417]{ - [417][417][417]Case6.super.(); - [326]() + [449:553]object Case6 extends [462:553][553]scala.AnyRef { + [553]def (): [462]Case6.type = [553]{ + [553][553][553]Case6.super.(); + [462]() }; - [330:373]def unapply([342:348]z: [345:348]): [334]Option[Int] = [365:373][365:369][365:369]new [365:369]Some[Int]([370:372]-1); - [377:378]{ - [377:378]case val x1: [377]Int(0) = [377:378]0; - [377:378]case5()[396:401]{ - [396:401] val o7: [396]Option[Int] = [396:401][396:401]Case6.unapply([396]x1); - [409:411]if ([396]o7.isEmpty.unary_!) - [409:411][409]matchEnd4([409:411]()) + [466:509]def unapply([478:484]z: [481:484]): [470]Option[Int] = [501:509][501:505][501:505]new [501:505]Some[Int]([506:508]-1); + [513:514]{ + [513:514]case val x1: [513]Int(0) = [513:514]0; + [513:514]case5()[532:537]{ + [532:537] val o7: [532]Option[Int] = [532:537][532:537]Case6.unapply([532]x1); + [545:547]if ([532]o7.isEmpty.unary_!) + [545:547][545]matchEnd4([545:547]()) else - [396][396]case6() + [532][532]case6() }; - [377:378]case6(){ - [377:378][377:378]matchEnd4([377:378]throw [377:378][377:378][377:378]new [377:378]MatchError([377:378]0)) + [513:514]case6(){ + [513:514][513:514]matchEnd4([513:514]throw [513:514][513:514][513:514]new [513:514]MatchError([513:514]0)) }; - [377:378]matchEnd4(x: [NoPosition]Unit){ - [377:378]x + [513:514]matchEnd4(x: [NoPosition]Unit){ + [513:514]x } } } diff --git a/test/files/run/t6288.scala b/test/files/run/t6288.scala index c807e7c8e5..0565e848ea 100644 --- a/test/files/run/t6288.scala +++ b/test/files/run/t6288.scala @@ -12,6 +12,7 @@ object Test extends DirectTest { | | "" match { | case Case3(nr) => () + | case x => throw new MatchError(x) | } |} |object Case4 { @@ -19,6 +20,7 @@ object Test extends DirectTest { | | "" match { | case Case4(nr) => () + | case x => throw new MatchError(x) | } |} |object Case5 { @@ -26,6 +28,7 @@ object Test extends DirectTest { | | "" match { | case Case4() => () + | case x => throw new MatchError(x) | } |} |object Case6 { diff --git a/test/files/run/t6695.scala b/test/files/run/t6695.scala index b527238a51..a773dd6c78 100644 --- a/test/files/run/t6695.scala +++ b/test/files/run/t6695.scala @@ -4,6 +4,7 @@ object Test extends App { case Array("a", "x", "c") => println("x") case Array("a", "b", "x") => println("a"); case Array("a", "d", _*) => println("wrongly positive") + case x => throw new MatchError(x) } assert(false, "match succeeded") } catch { @@ -14,5 +15,6 @@ object Test extends App { case Array("a", "x", "c") => println("x") case Array("a", "b", "x") => println("a"); case Array("a", "b", _*) => // okay + case x => throw new MatchError(x) } } diff --git a/test/files/run/t6863.scala b/test/files/run/t6863.scala index b93af89735..d6ac6e11f6 100644 --- a/test/files/run/t6863.scala +++ b/test/files/run/t6863.scala @@ -82,6 +82,7 @@ object Test { def labelDef() = { var x = 100 match { case 100 => try "42" finally () + case x => throw new MatchError(x) } assert({ () => x }.apply() == "42") } diff --git a/test/files/run/t7214.scala b/test/files/run/t7214.scala index b2ef53eeab..45befcc609 100644 --- a/test/files/run/t7214.scala +++ b/test/files/run/t7214.scala @@ -18,6 +18,7 @@ class Crash { // Crash via a Typed Pattern... (t: Any) match { case e: Alias => + case x => throw new MatchError(x) } // ... or via a Typed Extractor Pattern. diff --git a/test/files/run/t7912.scala b/test/files/run/t7912.scala index 3d603e0e97..cd65202513 100644 --- a/test/files/run/t7912.scala +++ b/test/files/run/t7912.scala @@ -3,6 +3,7 @@ case object A { override def toString = ??? } object Test { def foo: Int = (A: Any) match { case 0 => 0 + case x => throw new MatchError(x) } def main(args: Array[String]): Unit = { try { diff --git a/test/files/run/t8611a.scala b/test/files/run/t8611a.scala index 61a9f8d239..b4895bbaf8 100644 --- a/test/files/run/t8611a.scala +++ b/test/files/run/t8611a.scala @@ -14,5 +14,6 @@ object Test extends App { scrut match { case O.A => ??? case O.B => // spurious unreachable + case x => throw new MatchError(x) } } diff --git a/test/files/run/t8611c.scala b/test/files/run/t8611c.scala index a850b39dfe..c216d30c4a 100644 --- a/test/files/run/t8611c.scala +++ b/test/files/run/t8611c.scala @@ -18,6 +18,7 @@ object Test extends App { case B if "".isEmpty => ??? case A => case B => ??? + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t8637.check b/test/files/run/t8637.check deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/files/run/t8888.scala b/test/files/run/t8888.scala index 1bd36215e0..1ac421625f 100644 --- a/test/files/run/t8888.scala +++ b/test/files/run/t8888.scala @@ -5,7 +5,9 @@ class C { case x : C => (x: Any) match { case y : C => () => (x, y) // used to trigger a ClassFormatError under -Ydelambdafy:method + case y => throw new MatchError(y) } + case x => throw new MatchError(x) } } diff --git a/test/files/run/t9003.check b/test/files/run/t9003.check index d34d9ae2d1..45c8c72b02 100644 --- a/test/files/run/t9003.check +++ b/test/files/run/t9003.check @@ -14,7 +14,7 @@ t9003.scala:52: warning: match may not be exhaustive. It would fail on the following input: Sequence Sequence match { ^ -t9003.scala:68: warning: match may not be exhaustive. +t9003.scala:69: warning: match may not be exhaustive. It would fail on the following input: CaseSequence(_) CaseSequence(aArgs: _*) match { ^ diff --git a/test/files/run/t9003.scala b/test/files/run/t9003.scala index 3455653f5f..a6529db06b 100644 --- a/test/files/run/t9003.scala +++ b/test/files/run/t9003.scala @@ -60,6 +60,7 @@ object Test { case collection.Seq(_, i) => buffer(1) = 1 assertZero(i) // failed + case x => throw new MatchError(x) } case class CaseSequence(as: Int*) diff --git a/test/files/run/t9029b.scala b/test/files/run/t9029b.scala index 764d0771ec..f86fc6db7f 100644 --- a/test/files/run/t9029b.scala +++ b/test/files/run/t9029b.scala @@ -23,6 +23,7 @@ object Test { val x: AnyRef = new Foo(new Bar(Some(1), Some(2))) x match { case Foo(Bar(x1, x2)) => println(x1) + case x => throw new MatchError(x) } } def main(args: Array[String]): Unit = { diff --git a/test/files/run/t9029c.scala b/test/files/run/t9029c.scala index ccb51e23ae..140d430394 100644 --- a/test/files/run/t9029c.scala +++ b/test/files/run/t9029c.scala @@ -11,11 +11,13 @@ object Test { "" match { case Extractor(p) => val pp: Product2[Int, String] = p + case x => throw new MatchError(x) } "" match { case Extractor(x, y) => val xx: Int = x val yy: String = y + case x => throw new MatchError(x) } } } diff --git a/test/files/run/t9110.scala b/test/files/run/t9110.scala index 46a6502e9e..2e71309a79 100644 --- a/test/files/run/t9110.scala +++ b/test/files/run/t9110.scala @@ -19,6 +19,7 @@ object Test { case DomainB.Created(_) => throw null case DomainC.Created(_) => throw null case DomainA.Created(_) => // okay + case x => throw new MatchError(x) } } diff --git a/test/files/run/t9408.scala b/test/files/run/t9408.scala index 122bdd01d9..e195714730 100644 --- a/test/files/run/t9408.scala +++ b/test/files/run/t9408.scala @@ -32,6 +32,7 @@ class Outer { (new outer1.Member: Any) match { case _: outer2.Member => sys.error("wrong match!") case _: outer1.Member => // okay + case x => throw new MatchError(x) } // ... continuing on that theme, note that `Member` isn't considered as a local class, it is owned by a the class @@ -48,6 +49,7 @@ class Outer { (new localOuter1.Member: Any) match { case _: localOuter2.Member => sys.error("wrong match!") case _: localOuter1.Member => // okay + case x => throw new MatchError(x) } // Final member classes still lose the outer reference. assertNoFields(classOf[LocalOuter#FinalMember]) diff --git a/test/files/run/t9644.check b/test/files/run/t9644.check new file mode 100644 index 0000000000..3ea160b69d --- /dev/null +++ b/test/files/run/t9644.check @@ -0,0 +1,6 @@ +t9644.scala:14: warning: match may not be exhaustive. + d.tree match { + ^ +t9644.scala:20: warning: match may not be exhaustive. + r.tree match { + ^ diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index f5bba10d3d..686df9ddf0 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -251,6 +251,7 @@ class FancyTailCalls { def loop(n: Int): Int = if (n == 0) v else loop(n - 1) loop(x) == v } => true + case _ => throw new MatchError(x) } import FancyTailCalls._ diff --git a/test/files/run/typecheck.check b/test/files/run/typecheck.check deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/test/files/run/unapply.check b/test/files/run/unapply.check index 2649f90c76..84ab1daf5f 100644 --- a/test/files/run/unapply.check +++ b/test/files/run/unapply.check @@ -1,3 +1,6 @@ -unapply.scala:57: warning: comparing values of types Null and Null using `==` will always yield true +unapply.scala:62: warning: comparing values of types Null and Null using `==` will always yield true assert(doMatch2(b) == null) ^ +unapply.scala:104: warning: match may not be exhaustive. + lazyList match { + ^ diff --git a/test/files/run/unapply.scala b/test/files/run/unapply.scala index 5f6a3be2fd..545caa7c6b 100644 --- a/test/files/run/unapply.scala +++ b/test/files/run/unapply.scala @@ -38,18 +38,23 @@ object Foo { } def doMatch1(b:Bar) = b match { case Foo(s:Int, n:String) => (s,n) + case x => throw new MatchError(x) } def doMatch2(b:Bar) = b match { case Fii() => null + case x => throw new MatchError(x) } def doMatch3(b:Bar) = b match { case Faa(n:String) => n + case x => throw new MatchError(x) } def doMatch4(b:Bar) = (b:Any) match { case FaaPrecise(n:String) => n + case x => throw new MatchError(x) } def doMatch5(b:Bar) = (b:Any) match { case FaaPreciseSome(n:String) => n + case x => throw new MatchError(x) } def run(): Unit = { val b = new Bar @@ -61,6 +66,7 @@ object Foo { implicit val bc: Int = 3 assert(7 == (4 match { case VarFoo(x) => x + case x => throw new MatchError(x) })) } } @@ -81,14 +87,15 @@ object Mas { val b = new Baz assert((60,"too large") == (b match { case Gaz(s:Int, n:String) => (s,n) + case x => throw new MatchError(x) })) } } object LisSeqArr { def run(): Unit = { - assert((1,2) == ((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)})) - assert((1,2) == ((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)})) + assert((1,2) == ((List(1,2,3): Any) match { case List(x,y,_*) => (x,y) case x => throw new MatchError(x) })) + assert((1,2) == ((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y) case x => throw new MatchError(x) })) } } diff --git a/test/files/run/unapplyArray.check b/test/files/run/unapplyArray.check new file mode 100644 index 0000000000..6400dc8937 --- /dev/null +++ b/test/files/run/unapplyArray.check @@ -0,0 +1,3 @@ +unapplyArray.scala:26: warning: match may not be exhaustive. + val zl = zs match { + ^ diff --git a/test/files/run/uncheckedStable.check b/test/files/run/uncheckedStable.check new file mode 100644 index 0000000000..1a7b952a91 --- /dev/null +++ b/test/files/run/uncheckedStable.check @@ -0,0 +1,4 @@ +uncheckedStable.scala:9: warning: match may not be exhaustive. +It would fail on the following input: (x: Any forSome x not in (Test.this.A, Test.this.T, Test.this.o)) + def m(a: Any) = a match { + ^ diff --git a/test/files/run/virtpatmat_literal.check b/test/files/run/virtpatmat_literal.check index 1b832d16c5..611f1be310 100644 --- a/test/files/run/virtpatmat_literal.check +++ b/test/files/run/virtpatmat_literal.check @@ -1,6 +1,12 @@ virtpatmat_literal.scala:6: warning: unreachable code case `a` => println("FAILED") ^ +virtpatmat_literal.scala:15: warning: unreachable code + case x => throw new MatchError(x) + ^ +virtpatmat_literal.scala:22: warning: unreachable code + case x => throw new MatchError(x) + ^ OK OK OK diff --git a/test/files/run/virtpatmat_literal.scala b/test/files/run/virtpatmat_literal.scala index e94f7d627c..c91b4df792 100644 --- a/test/files/run/virtpatmat_literal.scala +++ b/test/files/run/virtpatmat_literal.scala @@ -4,6 +4,7 @@ object Test extends App { case 2 => println("FAILED") case 1 => println("OK") case `a` => println("FAILED") + case x => throw new MatchError(x) } val one = 1 @@ -11,12 +12,14 @@ object Test extends App { case 2 => println("FAILED") case `one` => println("OK") case 1 => println("FAILED") + case x => throw new MatchError(x) } 1 match { case 2 => println("FAILED") case Test.one => println("OK") case 1 => println("FAILED") + case x => throw new MatchError(x) } } diff --git a/test/files/run/virtpatmat_npe.check b/test/files/run/virtpatmat_npe.check index a0aba9318a..d86bac9de5 100644 --- a/test/files/run/virtpatmat_npe.check +++ b/test/files/run/virtpatmat_npe.check @@ -1 +1 @@ -OK \ No newline at end of file +OK diff --git a/test/files/run/virtpatmat_npe.scala b/test/files/run/virtpatmat_npe.scala index efa66f3286..b9fbace904 100644 --- a/test/files/run/virtpatmat_npe.scala +++ b/test/files/run/virtpatmat_npe.scala @@ -4,6 +4,7 @@ class C { values(0) match { case name: D => println("NOK: "+ name) // the outer check on D's outer should not cause a NPE case null => println("OK") + case x => throw new MatchError(x) } } diff --git a/test/files/run/virtpatmat_switch.check b/test/files/run/virtpatmat_switch.check index 6ded95c010..25d2dd6318 100644 --- a/test/files/run/virtpatmat_switch.check +++ b/test/files/run/virtpatmat_switch.check @@ -4,4 +4,4 @@ many got a got b got some letter -scala.MatchError: 5 (of class java.lang.Integer) \ No newline at end of file +scala.MatchError: 5 (of class java.lang.Integer) diff --git a/test/files/run/virtpatmat_switch.scala b/test/files/run/virtpatmat_switch.scala index 2f2e210d9e..d472deea78 100644 --- a/test/files/run/virtpatmat_switch.scala +++ b/test/files/run/virtpatmat_switch.scala @@ -25,7 +25,7 @@ object Test extends App { println(byteSwitch('b')) println(charSwitch('z')) - def implicitDefault(x: Int) = x match { + def implicitDefault(x: Int) = (x: @unchecked) match { case 0 => 0 } diff --git a/test/files/run/virtpatmat_typed.scala b/test/files/run/virtpatmat_typed.scala index 3693a81318..978ef11055 100644 --- a/test/files/run/virtpatmat_typed.scala +++ b/test/files/run/virtpatmat_typed.scala @@ -3,5 +3,6 @@ object Test extends App { case x: Int => println("FAILED") case x: String => println("OK "+ x) case x: String => println("FAILED") + case x => throw new MatchError(x) } } diff --git a/test/files/run/virtpatmat_unapply.scala b/test/files/run/virtpatmat_unapply.scala index 76e44938b4..9922f29bcc 100644 --- a/test/files/run/virtpatmat_unapply.scala +++ b/test/files/run/virtpatmat_unapply.scala @@ -9,11 +9,13 @@ object Test extends App { IntList(1, IntList(2, NilIL)) match { case IntList(a1, IntList(a2, IntList(a3, y))) => println(a1 + a2 + a3) case IntList(x, y) => println(x) + case x => throw new MatchError(x) } IntList(1, IntList(2, IntList(3, NilIL))) match { case IntList(a1, IntList(a2, IntList(a3, y))) => println(a1 + a2 + a3) case IntList(x, y) => println(x) + case x => throw new MatchError(x) } } diff --git a/test/junit/scala/tools/nsc/async/AnnotationDrivenAsyncTest.scala b/test/junit/scala/tools/nsc/async/AnnotationDrivenAsyncTest.scala index 2c7263837a..69acde313e 100644 --- a/test/junit/scala/tools/nsc/async/AnnotationDrivenAsyncTest.scala +++ b/test/junit/scala/tools/nsc/async/AnnotationDrivenAsyncTest.scala @@ -235,6 +235,7 @@ class AnnotationDrivenAsyncTest { | "" match { | case Extractor(a, b) => a == b | } + | case x => throw new MatchError(x) | } | } |} diff --git a/test/junit/scala/tools/nsc/backend/jvm/OptimizedBytecodeTest.scala b/test/junit/scala/tools/nsc/backend/jvm/OptimizedBytecodeTest.scala index ec43076dc1..02e8cf53eb 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/OptimizedBytecodeTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/OptimizedBytecodeTest.scala @@ -101,6 +101,7 @@ class OptimizedBytecodeTest extends BytecodeTesting { | def fillArray(arr: Array[V], v: V) = (arr: Any) match { | case x: Array[Int] => null | case x: Array[Long] => v.asInstanceOf[Long] + | case x => throw new MatchError(x) | } |} """.stripMargin diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala index c93e60d970..6135872a39 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/UnreachableCodeTest.scala @@ -251,7 +251,7 @@ class UnreachableCodeTest extends ClearAfterClass { def patmatDefaultLineNumber(): Unit = { val code = """class Test { - | def test = (this: AnyRef) match { + | def test = (this: AnyRef @unchecked) match { | case _: String => | "line4" // the synthetic `throw new MatchError` used to be positioned, here, despite the fact that patmat positions it at line 3. | } diff --git a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala index 421de94fd6..46ed47a6e3 100644 --- a/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala +++ b/test/junit/scala/tools/nsc/transform/patmat/PatmatBytecodeTest.scala @@ -98,6 +98,7 @@ class PatmatBytecodeTest extends BytecodeTesting { |class C { | def a = (Foo(1): Any) match { | case Foo(_: String) => + | case x => throw new MatchError(x) | } |} """.stripMargin diff --git a/test/scaladoc/run/t191.check b/test/scaladoc/run/t191.check index 3925a0d464..619c56180b 100644 --- a/test/scaladoc/run/t191.check +++ b/test/scaladoc/run/t191.check @@ -1 +1 @@ -Done. \ No newline at end of file +Done. diff --git a/test/scaladoc/run/t191.scala b/test/scaladoc/run/t191.scala index 734c422ca3..85c645d08b 100644 --- a/test/scaladoc/run/t191.scala +++ b/test/scaladoc/run/t191.scala @@ -76,6 +76,7 @@ object Test extends ScaladocModelTest { ).map( _.split("#").toSeq ).map({ case Seq(one) => scalaURL + "/" + one + ".html" case Seq(one, two) => scalaURL + "/" + one + ".html#" + two + case x => throw new MatchError(x) }) ++ Set(s"$jdkURL/java/lang/Throwable.html") def isExpectedExternalLink(l: EntityLink) = l.link match { diff --git a/test/scaladoc/run/tables.scala b/test/scaladoc/run/tables.scala index 634565f31c..c64321e92a 100644 --- a/test/scaladoc/run/tables.scala +++ b/test/scaladoc/run/tables.scala @@ -56,6 +56,7 @@ object Test extends ScaladocModelTest { case "" => Cell(Nil) case x: String => c(x) case None => Cell(Nil) + case x => throw new MatchError(x) } Row(cells) } diff --git a/test/tasty/run/src-2/tastytest/TestExports.scala b/test/tasty/run/src-2/tastytest/TestExports.scala index 8ec366da82..705feb9722 100644 --- a/test/tasty/run/src-2/tastytest/TestExports.scala +++ b/test/tasty/run/src-2/tastytest/TestExports.scala @@ -5,6 +5,7 @@ object TestExports extends Suite("TestExports") { def extract(scanned: String): String = scanned match { case s"scanned($inner)" => inner + case x => throw new MatchError(x) } def makePrinter(copier: Exports.Copier)(f: copier.type => copier.PrinterType): copier.PrinterType = diff --git a/test/tasty/run/src-2/tastytest/TestFancyColours.scala b/test/tasty/run/src-2/tastytest/TestFancyColours.scala index d5bbb5021f..e2924cbf2a 100644 --- a/test/tasty/run/src-2/tastytest/TestFancyColours.scala +++ b/test/tasty/run/src-2/tastytest/TestFancyColours.scala @@ -10,19 +10,23 @@ object TestFancyColours extends Suite("TestFancyColours") { def describe(c: Colour) = c match { case Colour.Pink => "Amazing!" case Colour.Red => "Yawn..." + case x => throw new MatchError(x) } def describePretty(c: Pretty) = c match { case Colour.Pink => "Amazing!" + case x => throw new MatchError(x) } def describeDull(c: Dull) = c match { case Colour.Red => "Yawn..." + case x => throw new MatchError(x) } def describeAny(x: Any) = x match { case p: Colour.Pink.type => Colour.describePink(p) case r: Colour.Red.type => Colour.describeRed(r) + case x => throw new MatchError(x) } def describePinkWrap(c: PinkWrap) = describePretty(c.toPink) diff --git a/test/tasty/run/src-2/tastytest/TestTermRefIns.scala b/test/tasty/run/src-2/tastytest/TestTermRefIns.scala index a08a07430a..6896177875 100644 --- a/test/tasty/run/src-2/tastytest/TestTermRefIns.scala +++ b/test/tasty/run/src-2/tastytest/TestTermRefIns.scala @@ -4,6 +4,7 @@ object TestTermRefIns extends Suite("TestTermRefIns") { def extractConfig(config: GenericConfig): String = config match { case embedded: EmbeddedConfig => embedded.config + case x => throw new MatchError(x) } test(assert(extractConfig(Configurations.defaultConfig) === "config"))