From 2f4f3d3db7c2eb9ed535065ffed8098a99de0278 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Mon, 5 Feb 2007 17:17:17 +0000 Subject: exhaustivity reworked --- test/files/neg/patmatexhaust.check | 11 +++++++---- test/files/neg/patmatexhaust.scala | 10 +++++++--- test/files/run/patmatnew.scala | 37 +++++++++++++++++++++++++++++++++++ test/files/run/regularpatmatnew.scala | 1 + 4 files changed, 52 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 40054bad9f..6a0eda5861 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -10,11 +10,14 @@ patmatexhaust.scala:24: warning: does not cover case {class Kult} patmatexhaust.scala:26: warning: does not cover case {class Qult} case {Qult(), Kult(_)} => // Qult missing ^ -patmatexhaust.scala:45: warning: does not cover case {object Gu} - def ma4(x:Deep) = x match { // missing cases: Gu +patmatexhaust.scala:44: warning: does not cover cases {object Gu,class Gp} + def ma4(x:Deep) = x match { // missing cases: Gu, Gp ^ -patmatexhaust.scala:57: error: unreachable code +patmatexhaust.scala:51: warning: does not cover case {class Gp} + case Ga => + ^ +patmatexhaust.scala:65: error: unreachable code case 1 => ^ -5 warnings found +6 warnings found one error found diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala index aaa32cda24..7370868363 100644 --- a/test/files/neg/patmatexhaust.scala +++ b/test/files/neg/patmatexhaust.scala @@ -27,7 +27,6 @@ class TestSealedExhaustive { // compile only //case {Qult(), Qult()} => } - sealed class Deep case object Ga extends Deep @@ -42,11 +41,11 @@ class TestSealedExhaustive { // compile only case _ => } - def ma4(x:Deep) = x match { // missing cases: Gu + def ma4(x:Deep) = x match { // missing cases: Gu, Gp case Ga => } - def zma5(x:Deep) = x match { // exhaustive + def ma5(x:Deep) = x match { // Gp case Gu => case _ if 1 == 0 => case Ga => @@ -56,6 +55,11 @@ class TestSealedExhaustive { // compile only case List(1,2) => case x :: xs => } + + def ma7 = List(1,2) match { //exhaustive + case 1::2::Nil => + case _ => + } def redundant = 1 match { // include this otherwise script won't test this in files/neg case 1 => case 1 => diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index 10b0021f0f..749b0bc21d 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -14,6 +14,7 @@ trait Shmeez extends AnyRef with Treez { } object Test { +/* import scala.testing.SUnit._ def main(args:Array[String]): Unit = { @@ -81,4 +82,40 @@ object Test { } } } + + + // these are exhaustive matches + // should not generate any warnings + def f[A](z:{Option[A],Option[A]}) = z match { + case {None,Some(x)} => 1 + case {Some(x),None } => 2 + case {Some(x),Some(y)} => 3 + case _ => 4 + } + + def g1[A](z:Option[List[A]]) = z match { + case Some(Nil) => true + case Some(x::Nil) => true + case _ => true + } + + def g2[A](z:Option[List[A]]) = z match { + case Some(x::Nil) => true + case Some(_) => false + case _ => true + } + + def h[A](x:{Option[A],Option[A]}) = x match { + case {None,_:Some[_]} => 1 + case {_:Some[_],None } => 2 + case {_:Some[_],_:Some[_]} => 3 + case _ => 4 + } +*/ + def i = List(1,2) match { + case List(1) => + case List(1,2,xs @ _*) => + case Nil => + } } + diff --git a/test/files/run/regularpatmatnew.scala b/test/files/run/regularpatmatnew.scala index a12ed5dfc6..a3401b2b7e 100644 --- a/test/files/run/regularpatmatnew.scala +++ b/test/files/run/regularpatmatnew.scala @@ -107,6 +107,7 @@ object Test { override def runTest() = { val res = (Bar(Foo()):Con) match { case Bar(xs@_*) => xs // this should be optimized away to a pattern Bar(xs) + case _ => Nil } assertEquals("res instance"+res.isInstanceOf[Seq[Con]]+" res(0)="+res(0), true, res.isInstanceOf[Seq[Foo]] && res(0) == Foo() ) } -- cgit v1.2.3