diff --git a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala index ac3de202439e..0660798a1d38 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/Logic.scala @@ -398,10 +398,9 @@ trait Logic extends Debugging { object gatherEqualities extends PropTraverser { override def apply(p: Prop) = p match { - case Eq(v, c) => - vars += v - v.registerEquality(c) - case _ => super.apply(p) + case Eq(v, NullConst) if !modelNull => vars += v // not modeling equality to null + case Eq(v, c) => vars += v; v.registerEquality(c) + case _ => super.apply(p) } } diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala index 71432b8ed6f1..52f519e82297 100644 --- a/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala +++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala @@ -246,10 +246,6 @@ trait MatchApproximation extends TreeAndTypeAnalysis with ScalaLogic with MatchT override def toString = s"T${id}C($prop)" } - class TreeMakersToPropsIgnoreNullChecks(root: Symbol) extends TreeMakersToProps(root) { - override def uniqueNonNullProp(p: Tree): Prop = True - } - // returns (tree, tests), where `tree` will be used to refer to `root` in `tests` class TreeMakersToProps(val root: Symbol) { prepareNewAnalysis() // reset hash consing for Var and Const @@ -537,7 +533,7 @@ trait MatchAnalysis extends MatchApproximation { val start = if (StatisticsStatics.areSomeColdStatsEnabled) statistics.startTimer(statistics.patmatAnaExhaust) else null var backoff = false - val approx = new TreeMakersToPropsIgnoreNullChecks(prevBinder) + val approx = new TreeMakersToProps(prevBinder) val symbolicCases = approx.approximateMatch(cases, approx.onUnknown { tm => approx.fullRewrite.applyOrElse[TreeMaker, Prop](tm, { case BodyTreeMaker(_, _) => True // irrelevant -- will be discarded by symbolCase later diff --git a/test/files/neg/t10019.check b/test/files/neg/t10019.check new file mode 100644 index 000000000000..9b861e903be1 --- /dev/null +++ b/test/files/neg/t10019.check @@ -0,0 +1,11 @@ +t10019.scala:4: warning: match may not be exhaustive. +It would fail on the following input: Foo(None) + def single(t: Foo): Nothing = t match { + ^ +t10019.scala:8: warning: match may not be exhaustive. +It would fail on the following input: (Foo(None), _) + def tuple(s: Foo, t: Foo): Nothing = (s, t) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/test/files/neg/t10019.flags b/test/files/neg/t10019.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/test/files/neg/t10019.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/test/files/neg/t10019.scala b/test/files/neg/t10019.scala new file mode 100644 index 000000000000..04cd95035f66 --- /dev/null +++ b/test/files/neg/t10019.scala @@ -0,0 +1,11 @@ +object Bug { + sealed case class Foo(e: Option[Int]) + + def single(t: Foo): Nothing = t match { + case Foo(Some(_)) => ??? + } + + def tuple(s: Foo, t: Foo): Nothing = (s, t) match { + case (Foo(Some(_)), _) => ??? + } +}