diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t4440.check | 13 | ||||
-rw-r--r-- | test/files/neg/t4440.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t4440.scala | 19 | ||||
-rw-r--r-- | test/files/neg/t5845.check | 5 | ||||
-rw-r--r-- | test/files/neg/t997.check | 8 | ||||
-rw-r--r-- | test/files/neg/t997.scala | 2 | ||||
-rw-r--r-- | test/files/neg/unchecked.check | 19 | ||||
-rw-r--r-- | test/files/neg/unchecked.flags | 1 | ||||
-rw-r--r-- | test/files/neg/unchecked.scala | 74 | ||||
-rw-r--r-- | test/files/neg/unchecked2.check | 12 | ||||
-rw-r--r-- | test/files/pos/t4881.scala | 31 | ||||
-rw-r--r-- | test/files/pos/t6089b.scala | 18 | ||||
-rw-r--r-- | test/files/pos/t6117.scala | 19 | ||||
-rw-r--r-- | test/files/pos/unchecked-a.flags | 1 | ||||
-rw-r--r-- | test/files/pos/unchecked-a.scala | 15 | ||||
-rw-r--r-- | test/files/run/t6090.scala | 6 | ||||
-rw-r--r-- | test/files/run/t6111.check | 2 | ||||
-rw-r--r-- | test/files/run/t6111.scala | 26 |
18 files changed, 254 insertions, 18 deletions
diff --git a/test/files/neg/t4440.check b/test/files/neg/t4440.check new file mode 100644 index 0000000000..2861dc3040 --- /dev/null +++ b/test/files/neg/t4440.check @@ -0,0 +1,13 @@ +t4440.scala:12: error: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") + ^ +t4440.scala:13: error: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") // this is the case we want + ^ +t4440.scala:16: error: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") + ^ +t4440.scala:17: error: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") // this is the case we want + ^ +four errors found diff --git a/test/files/neg/t4440.flags b/test/files/neg/t4440.flags new file mode 100644 index 0000000000..779916d58f --- /dev/null +++ b/test/files/neg/t4440.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t4440.scala b/test/files/neg/t4440.scala new file mode 100644 index 0000000000..383b141edd --- /dev/null +++ b/test/files/neg/t4440.scala @@ -0,0 +1,19 @@ +// constructors used to drop outer fields when they were not accessed +// however, how can you know (respecting separate compilation) that they're not accessed!? +class Outer { final class Inner } + +// the matches below require Inner's outer pointer +// until SI-4440 is fixed properly, we can't make this a run test +// in principle, the output should be "a\nb", but without outer checks it's "b\na" +object Test extends App { + val a = new Outer + val b = new Outer + (new a.Inner: Any) match { + case _: b.Inner => println("b") + case _: a.Inner => println("a") // this is the case we want + } + (new b.Inner: Any) match { + case _: a.Inner => println("a") + case _: b.Inner => println("b") // this is the case we want + } +} diff --git a/test/files/neg/t5845.check b/test/files/neg/t5845.check index 8c6100d6de..c0b402fccb 100644 --- a/test/files/neg/t5845.check +++ b/test/files/neg/t5845.check @@ -1,7 +1,4 @@ -t5845.scala:9: error: value +++ is not a member of Int - println(5 +++ 5) - ^ t5845.scala:15: error: value +++ is not a member of Int println(5 +++ 5) ^ -two errors found +one error found diff --git a/test/files/neg/t997.check b/test/files/neg/t997.check index c9fe0de756..186095f44a 100644 --- a/test/files/neg/t997.check +++ b/test/files/neg/t997.check @@ -1,13 +1,7 @@ -t997.scala:7: error: wrong number of arguments for object Foo -"x" match { case Foo(a) => Console.println(a) } - ^ -t997.scala:7: error: not found: value a -"x" match { case Foo(a) => Console.println(a) } - ^ t997.scala:13: error: wrong number of arguments for object Foo "x" match { case Foo(a, b, c) => Console.println((a,b,c)) } ^ t997.scala:13: error: not found: value a "x" match { case Foo(a, b, c) => Console.println((a,b,c)) } ^ -four errors found +two errors found diff --git a/test/files/neg/t997.scala b/test/files/neg/t997.scala index 42b46174d6..e8d10f4317 100644 --- a/test/files/neg/t997.scala +++ b/test/files/neg/t997.scala @@ -3,7 +3,7 @@ object Foo { def unapply(x : String) = Some(Pair(x, x)) } object Test extends App { -// Prints 'x'; ought not to compile (or maybe a should be the Pair?). +// Prints '(x, x)'. Should compile as per SI-6111. "x" match { case Foo(a) => Console.println(a) } // Prints '(x,x)' as expected. diff --git a/test/files/neg/unchecked.check b/test/files/neg/unchecked.check new file mode 100644 index 0000000000..34a11db1a0 --- /dev/null +++ b/test/files/neg/unchecked.check @@ -0,0 +1,19 @@ +unchecked.scala:18: error: non-variable type argument String in type pattern Iterable[String] is unchecked since it is eliminated by erasure + case xs: Iterable[String] => xs.head // unchecked + ^ +unchecked.scala:22: error: non-variable type argument Any in type pattern Set[Any] is unchecked since it is eliminated by erasure + case xs: Set[Any] => xs.head // unchecked + ^ +unchecked.scala:26: error: non-variable type argument Any in type pattern Map[Any,Any] is unchecked since it is eliminated by erasure + case xs: Map[Any, Any] => xs.head // unchecked + ^ +unchecked.scala:35: error: non-variable type argument List[Nothing] in type pattern Test.Contra[List[Nothing]] is unchecked since it is eliminated by erasure + case xs: Contra[List[Nothing]] => xs.head // unchecked + ^ +unchecked.scala:50: error: non-variable type argument String in type pattern Test.Exp[String] is unchecked since it is eliminated by erasure + case ArrayApply(x: Exp[Array[T]], _, j: Exp[String]) => x // unchecked + ^ +unchecked.scala:55: error: non-variable type argument Array[T] in type pattern Test.Exp[Array[T]] is unchecked since it is eliminated by erasure + case ArrayApply(x: Exp[Array[T]], _, _) => x // unchecked + ^ +6 errors found diff --git a/test/files/neg/unchecked.flags b/test/files/neg/unchecked.flags new file mode 100644 index 0000000000..464cc20ea6 --- /dev/null +++ b/test/files/neg/unchecked.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked
\ No newline at end of file diff --git a/test/files/neg/unchecked.scala b/test/files/neg/unchecked.scala new file mode 100644 index 0000000000..b50cdf9d7a --- /dev/null +++ b/test/files/neg/unchecked.scala @@ -0,0 +1,74 @@ +import language.existentials + +object Test { + class Def[T] + class Exp[T] + class Contra[-T] { def head[T1 <: T] : T1 = ??? } + class Cov[+T] { } + + case class ArrayApply[T](x: Exp[Array[T]], i: Exp[Int], j: Exp[_]) extends Def[T] + + val IntArrayApply = ArrayApply[Int](new Exp[Array[Int]], new Exp[Int], new Exp[Int]) + + def f(x: Any) = x match { + case xs: Iterable[Any] => xs.head // okay + case _ => 0 + } + def f2(x: Any) = x match { + case xs: Iterable[String] => xs.head // unchecked + case _ => 0 + } + def f3(x: Any) = x match { + case xs: Set[Any] => xs.head // unchecked + case _ => 0 + } + def f4(x: Any) = x match { + case xs: Map[Any, Any] => xs.head // unchecked + case _ => 0 + } + + def cf1(x: Any) = x match { + case xs: Contra[Nothing] => xs.head // okay + case _ => 0 + } + def cf2(x: Any) = x match { + case xs: Contra[List[Nothing]] => xs.head // unchecked + case _ => 0 + } + + def co1(x: List[Cov[List[Int]]]) = x match { + case _: Seq[Cov[Seq[Any]]] => true // okay + case _ => false + } + + def g[T](x: Def[T]) = x match { + case ArrayApply(x: Exp[Array[T]], i: Exp[Int], _) => x // okay + case _ => 0 + } + + def g2[T](x: Def[T]) = x match { + case ArrayApply(x: Exp[Array[T]], _, j: Exp[String]) => x // unchecked + case _ => 0 + } + + def g3[T](x: Any) = x match { + case ArrayApply(x: Exp[Array[T]], _, _) => x // unchecked + case _ => 0 + } + + def g4 = IntArrayApply match { + case ArrayApply(x: Exp[Array[Int]], _, _) => x // okay + case _ => () + } + def g5[T](x: ArrayApply[Int]) = x match { + case ArrayApply(x: Exp[Array[Int]], _, _) => x // okay + case _ => 0 + } + + // Nope + // + // def g5 = IntArrayApply match { + // case ArrayApply(x: Exp[Array[String]], _, _) => x // nope + // case _ => () + // } +} diff --git a/test/files/neg/unchecked2.check b/test/files/neg/unchecked2.check index 2c0be9ce00..e37865928e 100644 --- a/test/files/neg/unchecked2.check +++ b/test/files/neg/unchecked2.check @@ -1,19 +1,19 @@ -unchecked2.scala:2: error: non variable type-argument Int in type Option[Int] is unchecked since it is eliminated by erasure +unchecked2.scala:2: error: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[Int]] ^ -unchecked2.scala:3: error: non variable type-argument String in type Option[String] is unchecked since it is eliminated by erasure +unchecked2.scala:3: error: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[String]] ^ -unchecked2.scala:4: error: non variable type-argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure +unchecked2.scala:4: error: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[List[String]]] ^ -unchecked2.scala:5: error: non variable type-argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure +unchecked2.scala:5: error: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[List[Int => String]]] ^ -unchecked2.scala:6: error: non variable type-argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure +unchecked2.scala:6: error: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[(String, Double)]] ^ -unchecked2.scala:7: error: non variable type-argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure +unchecked2.scala:7: error: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure Some(123).isInstanceOf[Option[String => Double]] ^ 6 errors found diff --git a/test/files/pos/t4881.scala b/test/files/pos/t4881.scala new file mode 100644 index 0000000000..46cfad9793 --- /dev/null +++ b/test/files/pos/t4881.scala @@ -0,0 +1,31 @@ +class Contra[-T] +trait A +trait B extends A +trait C extends B + +// test improved variance inference: first try formals to see in which variance positions the type param appears; +// only when that fails to determine variance, look at result type +object Test { + def contraLBUB[a >: C <: A](): Contra[a] = null + def contraLB[a >: C](): Contra[a] = null + +{ + val x = contraLBUB() //inferred Contra[C] instead of Contra[A] + val x1: Contra[A] = x +} + +{ + val x = contraLB() //inferred Contra[C] instead of Contra[Any] + val x1: Contra[Any] = x +} + +{ + val x = contraLBUB // make sure it does the same thing as its ()-less counterpart + val x1: Contra[A] = x +} + +{ + val x = contraLB + val x1: Contra[Any] = x +} +} diff --git a/test/files/pos/t6089b.scala b/test/files/pos/t6089b.scala new file mode 100644 index 0000000000..ff7ca157eb --- /dev/null +++ b/test/files/pos/t6089b.scala @@ -0,0 +1,18 @@ +// this crazy code simply tries to nest pattern matches so that the last call is in a tricky-to-determine +// tail position (my initial tightenign of tailpos detection for SI-6089 ruled this out) +class BKTree { + @annotation.tailrec + final def -?-[AA](a: AA): Boolean = this match { + case BKTreeEmpty => false + case BKTreeNode(v) => { + val d = 1 + d == 0 || ( Map(1 -> this,2 -> this,3 -> this) get d match { + case None => false + case Some(w) => w -?- a // can tail call here (since || is shortcutting) + }) + } + } +} + +object BKTreeEmpty extends BKTree +case class BKTreeNode[A](v: A) extends BKTree
\ No newline at end of file diff --git a/test/files/pos/t6117.scala b/test/files/pos/t6117.scala new file mode 100644 index 0000000000..6aca84f72c --- /dev/null +++ b/test/files/pos/t6117.scala @@ -0,0 +1,19 @@ +package test + +trait ImportMe { + def foo(i: Int) = 1 + def foo(s: String) = 2 +} + +class Test(val importMe: ImportMe) { + import importMe._ + import importMe._ + + // A.scala:12: error: reference to foo is ambiguous; + // it is imported twice in the same scope by + // import importMe._ + // and import importMe._ + // println(foo(1)) + // ^ + println(foo(1)) +} diff --git a/test/files/pos/unchecked-a.flags b/test/files/pos/unchecked-a.flags new file mode 100644 index 0000000000..779916d58f --- /dev/null +++ b/test/files/pos/unchecked-a.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings
\ No newline at end of file diff --git a/test/files/pos/unchecked-a.scala b/test/files/pos/unchecked-a.scala new file mode 100644 index 0000000000..deceb91c36 --- /dev/null +++ b/test/files/pos/unchecked-a.scala @@ -0,0 +1,15 @@ +trait Y +trait Z extends Y +class X[+A <: Y] + +object Test { + def f1(x: X[_ <: Y]) = x match { + case _: X[Any] => // looks a little funny; `Any` is outside the bounds for `A` + } + def f2(x: X[_ <: Y]) = x match { + case _: X[Y] => // looks better, let's allow this (too) + } + + // NonLocalReturnControl[_] warnings + def foo: Int = List(0).foldLeft(0){case _ => return 0} +} diff --git a/test/files/run/t6090.scala b/test/files/run/t6090.scala new file mode 100644 index 0000000000..e7dbb36a05 --- /dev/null +++ b/test/files/run/t6090.scala @@ -0,0 +1,6 @@ +class X { def ==(other: X) = true } +class V(val x: X) extends AnyVal +object Test extends { + def main(args: Array[String]) = + assert((new V(new X) == new V(new X))) +} diff --git a/test/files/run/t6111.check b/test/files/run/t6111.check new file mode 100644 index 0000000000..7fd2e33526 --- /dev/null +++ b/test/files/run/t6111.check @@ -0,0 +1,2 @@ +(8,8) +(x,x) diff --git a/test/files/run/t6111.scala b/test/files/run/t6111.scala new file mode 100644 index 0000000000..7cceea1d09 --- /dev/null +++ b/test/files/run/t6111.scala @@ -0,0 +1,26 @@ +// slightly overkill, but a good test case for implicit resolution in extractor calls, +// along with the real fix: an extractor pattern with 1 sub-pattern should type check for all extractors +// that return Option[T], whatever T (even if it's a tuple) +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]) + } +} + +class FooHasType[S, T] +object FooHasType { + implicit object int extends FooHasType[Int, (Int, Int)] +} + +// resurrected from neg/t997 +object Foo997 { def unapply(x : String): Option[(String, String)] = Some((x, x)) } + +object Test extends App { + val x = 8 + println(x match { + case Foo(p) => p // p should be a pair of Int + }) + + // Prints '(x, x)' + "x" match { case Foo997(a) => println(a) } +}
\ No newline at end of file |