Reverse -Xlint:strict-unsealed-patmat into -Xno-unsealed-patmat-analysis

This commit is contained in:
Dale Wijnand 2020-09-15 10:24:32 +01:00
parent cb391c292a
commit 0416c57a01
139 changed files with 420 additions and 163 deletions

View File

@ -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"),

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -20,6 +20,7 @@ object Test extends App { test
case _ => foo; ()
}
()
case x => throw new MatchError(x)
}
()
}, Duration.Inf)

View File

@ -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

View File

@ -119,6 +119,7 @@ package scala.async.run.match0 {
await(0)
case buf: Double =>
await(2)
case x => throw new MatchError(x)
}
})

View File

@ -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] _
^

View File

@ -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

View File

@ -34,6 +34,7 @@ object Test {
value(Some(1))
"foo" match {
case x if "".isEmpty => x
case x => throw new MatchError(x)
}
}: AnyRef
})

View File

@ -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

View File

@ -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)

View File

@ -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[_]]

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)
^

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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 _ =>
}
}

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -1,4 +1,4 @@
// scalac: -Xlint:stars-align -Xfatal-warnings
// scalac: -Xlint:stars-align -Xfatal-warnings -Xno-unsealed-patmat-analysis
//

View File

@ -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)

View File

@ -1,4 +1,4 @@
// scalac: -Xfatal-warnings
// scalac: -Xfatal-warnings -Xno-unsealed-patmat-analysis
//
object Unchecked {
(null: Any) match {

View File

@ -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

View File

@ -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

View File

@ -1,3 +1,4 @@
// scalac: -Xno-unsealed-patmat-analysis
import annotation._
object Tail {

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -6,5 +6,6 @@ class View[C[A]] { }
object Test {
(null: Any) match {
case v: View[_] =>
case _ =>
}
}

View File

@ -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

View File

@ -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) }
}

View File

@ -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)
}
}

View File

@ -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"))

View File

@ -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 {

View File

@ -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

View File

@ -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)

View File

@ -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]

View File

@ -15,5 +15,6 @@ object Test extends App {
42 match {
case ExtractorMacro(x) => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -15,5 +15,6 @@ object Test extends App {
42 match {
case ExtractorMacro(x) => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -2,5 +2,6 @@
object Test extends App {
42 match {
case Extractor(a) => println(a)
case x => throw new MatchError(x)
}
}

View File

@ -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)
}
}

View File

@ -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)))),

View File

@ -1,5 +1,6 @@
object Test extends App {
42 match {
case Extractor(x) => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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 }

View File

@ -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 =>
^

View File

@ -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)
}
}
}

View File

@ -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}"
}

View File

@ -5,18 +5,18 @@
[2302][2302][2302]C.super.<init>();
[9]()
};
[103:904]def commonSubPattern([124:130]x: [127:130]<type: [127:130]scala.Any>): [107]AnyVal = [205:206]{
[205:206]<synthetic> var rc6: [205]Boolean = [205]false;
[205:206]<synthetic> <stable> var x3: [205]String = [205][205][205]null.asInstanceOf[[205]String];
[205:206]{
[205:206]case <synthetic> val x1: [205]Any = [205:206]x;
[205:206]case8(){
[103:904]def commonSubPattern([124:130]x: [127:130]<type: [127:130]scala.Any>): [107]AnyVal = [206:220]{
[206:220]<synthetic> var rc6: [211]Boolean = [211]false;
[206:220]<synthetic> <stable> var x3: [211]String = [211][211][211]null.asInstanceOf[[211]String];
[206:220]{
[206:220]case <synthetic> val x1: [211]Any = [206:220]([206:207]x: [211]<type: [NoPosition][206:207]x: @[211:220]unchecked>);
[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]<type: [1020:1023]scala.Any>): [1007]Any = [1027:1028]{
[1027:1028]case <synthetic> val x1: [1027]Any = [1027:1028]x;
[1027:1028]case6(){
[1003:1306]def extractor([1017:1023]x: [1020:1023]<type: [1020:1023]scala.Any>): [1007]Any = [1028:1041]{
[1028:1041]case <synthetic> val x1: [1032]Any = [1028:1041]([1028:1029]x: [1032]<type: [NoPosition][1028:1029]x: @[1032:1041]unchecked>);
[1028:1041]case6(){
[1112:1126]if ([1120][1120]x1.isInstanceOf[[1120]Product2[T1,T2]])
[1112:1126]{
[1112:1126]<synthetic> 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 {

View File

@ -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 //
| } //

View File

@ -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)))}")
}
}
}

View File

@ -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)
}
}
}

View File

@ -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]) = {

View File

@ -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)

View File

@ -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)
}

View File

@ -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)

View File

@ -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)

View File

@ -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)
}
}
}

View File

@ -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 = {

View File

@ -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

View File

@ -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(_) => () }
"""
}

View File

@ -26,6 +26,7 @@ object Test {
case SubclassMatch(p) => p
case StandardMatch(p) => p
case x => throw new MatchError(x)
}
}
}

View File

@ -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

View File

@ -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 {

View File

@ -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)
}
}
}

View File

@ -1,5 +1,5 @@
object Test extends App {
trait T
sealed trait T
trait TA
trait TB

View File

@ -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)
}
}
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -2,5 +2,6 @@ object Test extends App {
import Interpolation._
2 match {
case t"$x" => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -3,5 +3,6 @@ object Test extends App {
import Interpolation._
2 match {
case t"$x" => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -3,5 +3,6 @@ object Test extends App {
import Interpolation._
42 match {
case t"$x" => println(x)
case x => throw new MatchError(x)
}
}

View File

@ -12,6 +12,7 @@ trait Trees {
tree match {
case TypeTree(_) => println("lolwut")
case null => println("correct")
case x => throw new MatchError(x)
}
}

View File

@ -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
}

View File

@ -1,3 +1,4 @@
// scalac: -Xno-unsealed-patmat-analysis
class LiteralNode(val value: Any)
object LiteralNode {

View File

@ -2,6 +2,7 @@ class A { Self =>
val ok = "ok"
this match {
case me@Self => println(me.ok)
case x => throw new MatchError(x)
}
}

View File

@ -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) }
}

View File

@ -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]<empty> {
[0:105]object Case3 extends [13:105][106]scala.AnyRef {
[106]def <init>(): [13]Case3.type = [106]{
[106][106][106]Case3.super.<init>();
[0:553]package [0:0]<empty> {
[0:151]object Case3 extends [13:151][152]scala.AnyRef {
[152]def <init>(): [13]Case3.type = [152]{
[152][152][152]Case3.super.<init>();
[13]()
};
[17:60]def unapply([29:35]z: [32:35]<type: [32:35]scala.Any>): [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 <init>(): [119]Case4.type = [217]{
[217][217][217]Case4.super.<init>();
[119]()
[152:308]object Case4 extends [165:308][309]scala.AnyRef {
[309]def <init>(): [165]Case4.type = [309]{
[309][309][309]Case4.super.<init>();
[165]()
};
[123:171]def unapplySeq([138:144]z: [141:144]<type: [141:144]scala.Any>): [127]Option[List[Int]] = [167:171]scala.None;
[175:177]{
[175:177]case <synthetic> val x1: [175]String("") = [175:177]"";
[175:177]case5(){
[195:204]if ([200][200][200]"".ne([200]null))
[195:200]{
[195:200]<synthetic> 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]<type: [187:190]scala.Any>): [173]Option[List[Int]] = [213:217]scala.None;
[221:223]{
[221:223]case <synthetic> val x1: [221]String("") = [221:223]"";
[221:223]case5(){
[241:250]if ([246][246][246]"".ne([246]null))
[241:246]{
[241:246]<synthetic> 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 <init>(): [230]Case5.type = [313]{
[313][313][313]Case5.super.<init>();
[230]()
[309:448]object Case5 extends [322:448][449]scala.AnyRef {
[449]def <init>(): [322]Case5.type = [449]{
[449][449][449]Case5.super.<init>();
[322]()
};
[234:269]def unapply([246:252]z: [249:252]<type: [249:252]scala.Any>): [238]Boolean = [265:269]true;
[273:275]{
[273:275]case <synthetic> val x1: [273]String("") = [273:275]"";
[273:275]case5(){
[293:300]if ([298][298][298]"".ne([298]null))
[293:298]{
[293:298]<synthetic> 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]<type: [341:344]scala.Any>): [330]Boolean = [357:361]true;
[365:367]{
[365:367]case <synthetic> val x1: [365]String("") = [365:367]"";
[365:367]case5(){
[385:392]if ([390][390][390]"".ne([390]null))
[385:390]{
[385:390]<synthetic> 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 <init>(): [326]Case6.type = [417]{
[417][417][417]Case6.super.<init>();
[326]()
[449:553]object Case6 extends [462:553][553]scala.AnyRef {
[553]def <init>(): [462]Case6.type = [553]{
[553][553][553]Case6.super.<init>();
[462]()
};
[330:373]def unapply([342:348]z: [345:348]<type: [345:348]scala.Int>): [334]Option[Int] = [365:373][365:369][365:369]new [365:369]Some[Int]([370:372]-1);
[377:378]{
[377:378]case <synthetic> val x1: [377]Int(0) = [377:378]0;
[377:378]case5()[396:401]{
[396:401]<synthetic> 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]<type: [481:484]scala.Int>): [470]Option[Int] = [501:509][501:505][501:505]new [501:505]Some[Int]([506:508]-1);
[513:514]{
[513:514]case <synthetic> val x1: [513]Int(0) = [513:514]0;
[513:514]case5()[532:537]{
[532:537]<synthetic> 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
}
}
}

View File

@ -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 {

Some files were not shown because too many files have changed in this diff Show More