diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-05-23 02:42:06 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-05-23 02:42:06 -0700 |
commit | cebf241ad87358b0e8d2804750a4ac36e76f7091 (patch) | |
tree | 29e04607f5bf666bed4f8d78d1b757f0763fdd1e /test/files/pos | |
parent | 2e7daa10097246c03df1f77aebc85f1ecdebb7e9 (diff) | |
parent | 3f7b8b58748eb70aec4269f1ef63853b5ad4af60 (diff) | |
download | scala-cebf241ad87358b0e8d2804750a4ac36e76f7091.tar.gz scala-cebf241ad87358b0e8d2804750a4ac36e76f7091.tar.bz2 scala-cebf241ad87358b0e8d2804750a4ac36e76f7091.zip |
Merge pull request #601 from adriaanm/3f7b8b58748eb70aec4269f1ef63853b5ad4af60
virtpatmat: treemaker approximation refactorings and exhaustivity
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/exhaust_alternatives.flags | 1 | ||||
-rw-r--r-- | test/files/pos/exhaust_alternatives.scala | 10 | ||||
-rw-r--r-- | test/files/pos/exhaustive_heuristics.scala | 16 | ||||
-rw-r--r-- | test/files/pos/no-widen-locals.scala | 19 | ||||
-rw-r--r-- | test/files/pos/t3097.scala | 31 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exhaust.scala | 24 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exhaust_unchecked.flags | 1 | ||||
-rw-r--r-- | test/files/pos/virtpatmat_exhaust_unchecked.scala | 24 |
8 files changed, 76 insertions, 50 deletions
diff --git a/test/files/pos/exhaust_alternatives.flags b/test/files/pos/exhaust_alternatives.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/pos/exhaust_alternatives.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/exhaust_alternatives.scala b/test/files/pos/exhaust_alternatives.scala new file mode 100644 index 0000000000..cc81d0be7d --- /dev/null +++ b/test/files/pos/exhaust_alternatives.scala @@ -0,0 +1,10 @@ +sealed abstract class X +sealed case class A(x: Boolean) extends X +case object B extends X + +object Test { + def test(x: X) = x match { + case A(true) => + case A(false) | B => + } +}
\ No newline at end of file diff --git a/test/files/pos/exhaustive_heuristics.scala b/test/files/pos/exhaustive_heuristics.scala new file mode 100644 index 0000000000..f6bea455a5 --- /dev/null +++ b/test/files/pos/exhaustive_heuristics.scala @@ -0,0 +1,16 @@ +// tests exhaustivity doesn't give warnings (due to its heuristic rewrites kicking in or it backing off) +object Test { + // List() => Nil + List(1) match { + case List() => + case x :: xs => + } + + // we don't look into guards + val turnOffChecks = true + List(1) match { + case _ if turnOffChecks => + } + + // TODO: we back off when there are any user-defined extractors +}
\ No newline at end of file diff --git a/test/files/pos/no-widen-locals.scala b/test/files/pos/no-widen-locals.scala deleted file mode 100644 index 013e63f0a2..0000000000 --- a/test/files/pos/no-widen-locals.scala +++ /dev/null @@ -1,19 +0,0 @@ -// Worked from r23262 until that was reverted somewhere -// around r25016. -import annotation.switch - -object Test { - def f(x: Int) = { - val X1 = 5 - val X2 = 10 - val X3 = 15 - val X4 = 20 - - (x: @switch) match { - case X1 => 1 - case X2 => 2 - case X3 => 3 - case X4 => 4 - } - } -} diff --git a/test/files/pos/t3097.scala b/test/files/pos/t3097.scala deleted file mode 100644 index a034b960f7..0000000000 --- a/test/files/pos/t3097.scala +++ /dev/null @@ -1,31 +0,0 @@ -package seal - -sealed trait ISimpleValue - -sealed trait IListValue extends ISimpleValue { - def items: List[IAtomicValue[_]] -} -sealed trait IAtomicValue[O] extends ISimpleValue { - def data: O -} - -sealed trait IAbstractDoubleValue[O] extends IAtomicValue[O] { } -sealed trait IDoubleValue extends IAbstractDoubleValue[Double] - -case class ListValue(val items: List[IAtomicValue[_]]) extends IListValue -class DoubleValue(val data: Double) extends IDoubleValue { - def asDouble = data -} - -object Test { - /** - * @param args the command line arguments - */ - def main(args: Array[String]): Unit = { - val v: ISimpleValue = new DoubleValue(1) - v match { - case m: IListValue => println("list") - case a: IAtomicValue[_] => println("atomic") - } - } -} diff --git a/test/files/pos/virtpatmat_exhaust.scala b/test/files/pos/virtpatmat_exhaust.scala new file mode 100644 index 0000000000..a2f47c88c8 --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = opt match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} diff --git a/test/files/pos/virtpatmat_exhaust_unchecked.flags b/test/files/pos/virtpatmat_exhaust_unchecked.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust_unchecked.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/pos/virtpatmat_exhaust_unchecked.scala b/test/files/pos/virtpatmat_exhaust_unchecked.scala new file mode 100644 index 0000000000..641f2b4f9a --- /dev/null +++ b/test/files/pos/virtpatmat_exhaust_unchecked.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = (opt: @unchecked) match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + // case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} |