diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/t6663.check | 6 | ||||
-rw-r--r-- | test/files/neg/t6663.scala | 19 | ||||
-rw-r--r-- | test/files/pos/t6551.scala | 13 | ||||
-rw-r--r-- | test/files/run/t6023.check | 12 | ||||
-rw-r--r-- | test/files/run/t6023.scala | 17 | ||||
-rw-r--r-- | test/files/run/t6150.scala | 44 | ||||
-rw-r--r-- | test/files/run/t6632.check | 3 | ||||
-rw-r--r-- | test/files/run/t6632.scala | 29 | ||||
-rw-r--r-- | test/files/run/t6633.check | 3 | ||||
-rw-r--r-- | test/files/run/t6633.scala | 33 | ||||
-rw-r--r-- | test/files/run/t6634.check | 31 | ||||
-rw-r--r-- | test/files/run/t6634.scala | 80 | ||||
-rw-r--r-- | test/files/run/t6663.check | 1 | ||||
-rw-r--r-- | test/files/run/t6663.scala | 17 | ||||
-rw-r--r-- | test/files/run/t6673.check | 1 | ||||
-rw-r--r-- | test/files/run/t6673.scala | 5 | ||||
-rw-r--r-- | test/files/run/t6695.scala | 18 | ||||
-rw-r--r-- | test/files/run/t6706.scala | 14 |
18 files changed, 346 insertions, 0 deletions
diff --git a/test/files/neg/t6663.check b/test/files/neg/t6663.check new file mode 100644 index 0000000000..aa4faa4a46 --- /dev/null +++ b/test/files/neg/t6663.check @@ -0,0 +1,6 @@ +t6663.scala:16: error: type mismatch; + found : String + required: Int + var v = new C(42).foo[String].get :Int + ^ +one error found diff --git a/test/files/neg/t6663.scala b/test/files/neg/t6663.scala new file mode 100644 index 0000000000..4a358dfbc5 --- /dev/null +++ b/test/files/neg/t6663.scala @@ -0,0 +1,19 @@ +import language.dynamics + +class C(v: Any) extends Dynamic { + def selectDynamic[T](n: String): Option[T] = Option(v.asInstanceOf[T]) + def applyDynamic[T](n: String)(): Option[T] = Option(v.asInstanceOf[T]) +} + +object Test extends App { + // this should be converted to + // C(42).selectDynamic[String]("foo").get + // causing a compile error. + + // but, before fixing SI-6663, became + // C(42).selectDynamic("foo").get, ignoring + // the [String] type parameter + var v = new C(42).foo[String].get :Int + println(v) +} + diff --git a/test/files/pos/t6551.scala b/test/files/pos/t6551.scala new file mode 100644 index 0000000000..fb68663809 --- /dev/null +++ b/test/files/pos/t6551.scala @@ -0,0 +1,13 @@ +import language.dynamics + +object Test { + def main(args: Array[String]) { + class Lenser[T] extends Dynamic { + def selectDynamic(propName: String) = ??? + } + + def lens[T] = new Lenser[T] + + val qq = lens[String] + } +} diff --git a/test/files/run/t6023.check b/test/files/run/t6023.check new file mode 100644 index 0000000000..ee93565234 --- /dev/null +++ b/test/files/run/t6023.check @@ -0,0 +1,12 @@ +{ + abstract trait Foo extends AnyRef { + <stable> <accessor> def a: Int + }; + () +} +{ + abstract trait Foo extends AnyRef { + <stable> <accessor> def a: Int + }; + () +} diff --git a/test/files/run/t6023.scala b/test/files/run/t6023.scala new file mode 100644 index 0000000000..07af3685a5 --- /dev/null +++ b/test/files/run/t6023.scala @@ -0,0 +1,17 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + // test 1: reify + val tree = reify{ trait Foo { val a: Int } }.tree + println(tree.toString) + + // test 2: import and typecheck + val toolbox = cm.mkToolBox() + val ttree = toolbox.typeCheck(tree) + println(ttree.toString) + + // test 3: import and compile + toolbox.eval(tree) +} diff --git a/test/files/run/t6150.scala b/test/files/run/t6150.scala new file mode 100644 index 0000000000..bd8af5d460 --- /dev/null +++ b/test/files/run/t6150.scala @@ -0,0 +1,44 @@ + + + + +object Test { + import collection.{ immutable, mutable, generic } + def TheOneTrueCBF = collection.IndexedSeq.ReusableCBF + + val cbf1 = implicitly[generic.CanBuildFrom[immutable.Vector[Int], Int, collection.IndexedSeq[Int]]] + val cbf2 = implicitly[generic.CanBuildFrom[immutable.IndexedSeq[Int], Int, collection.IndexedSeq[Int]]] + val cbf3 = implicitly[generic.CanBuildFrom[collection.IndexedSeq[Int], Int, collection.IndexedSeq[Int]]] + + val cbf4 = implicitly[generic.CanBuildFrom[immutable.Vector[Int], Int, immutable.IndexedSeq[Int]]] + val cbf5 = implicitly[generic.CanBuildFrom[immutable.Vector[Int], Int, immutable.Vector[Int]]] + val cbf6 = implicitly[generic.CanBuildFrom[immutable.IndexedSeq[Int], Int, immutable.IndexedSeq[Int]]] + + def check[C](v: C) = { + assert(v == Vector(1, 2, 3, 4)) + assert(v.isInstanceOf[Vector[_]]) + } + def checkRealMccoy(x: AnyRef) = { + assert(x eq TheOneTrueCBF, cbf1) + } + + val v = immutable.Vector(1, 2, 3) + val iiv: immutable.IndexedSeq[Int] = immutable.Vector(1, 2, 3) + val iv: IndexedSeq[Int] = immutable.Vector(1, 2, 3) + + def main(args: Array[String]): Unit = { + List(cbf1, cbf2, cbf3, cbf4, cbf5, cbf6) foreach checkRealMccoy + check(v.:+(4)(cbf1)) + check(v.:+(4)(cbf2)) + check(v.:+(4)(cbf3)) + + check(iiv.:+(4)(cbf2)) + check(iiv.:+(4)(cbf3)) + + check(iv.:+(4)(cbf3)) + } +} + + + + diff --git a/test/files/run/t6632.check b/test/files/run/t6632.check new file mode 100644 index 0000000000..1f084b1dac --- /dev/null +++ b/test/files/run/t6632.check @@ -0,0 +1,3 @@ +java.lang.IndexOutOfBoundsException: -1 +java.lang.IndexOutOfBoundsException: -2 +java.lang.IndexOutOfBoundsException: -3 diff --git a/test/files/run/t6632.scala b/test/files/run/t6632.scala new file mode 100644 index 0000000000..c1c8d4abe0 --- /dev/null +++ b/test/files/run/t6632.scala @@ -0,0 +1,29 @@ +object Test extends App { + import collection.mutable.ListBuffer + + def newLB = ListBuffer('a, 'b, 'c, 'd, 'e) + + val lb0 = newLB + + try { + lb0.insert(-1, 'x) + } catch { + case ex: IndexOutOfBoundsException => println(ex) + } + + val lb1 = newLB + + try { + lb1.insertAll(-2, Array('x, 'y, 'z)) + } catch { + case ex: IndexOutOfBoundsException => println(ex) + } + + val lb2 = newLB + + try { + lb2.update(-3, 'u) + } catch { + case ex: IndexOutOfBoundsException => println(ex) + } +}
\ No newline at end of file diff --git a/test/files/run/t6633.check b/test/files/run/t6633.check new file mode 100644 index 0000000000..1ff8cdbc44 --- /dev/null +++ b/test/files/run/t6633.check @@ -0,0 +1,3 @@ +java.lang.IndexOutOfBoundsException: 9 +replStringOf OK +length OK diff --git a/test/files/run/t6633.scala b/test/files/run/t6633.scala new file mode 100644 index 0000000000..bd993c8d88 --- /dev/null +++ b/test/files/run/t6633.scala @@ -0,0 +1,33 @@ +object Test extends App { + import collection.mutable.ListBuffer + + def newLB = ListBuffer('a, 'b, 'c, 'd, 'e) + + val lb0 = newLB + + try { + lb0.insert(9, 'x) + } catch { + case ex: IndexOutOfBoundsException => println(ex) + } + + val lb1 = newLB + + try { + lb1.insert(9, 'x) + } catch { + case ex: IndexOutOfBoundsException => + } + + val replStr = scala.runtime.ScalaRunTime.replStringOf(lb1, 100) + if (replStr == "ListBuffer('a, 'b, 'c, 'd, 'e)\n") + println("replStringOf OK") + else + println("replStringOf FAILED: " + replStr) + + val len = lb1.length + if (len == 5) + println("length OK") + else + println("length FAILED: " + len) +}
\ No newline at end of file diff --git a/test/files/run/t6634.check b/test/files/run/t6634.check new file mode 100644 index 0000000000..f6cbb30c67 --- /dev/null +++ b/test/files/run/t6634.check @@ -0,0 +1,31 @@ +Trying lb0 ... +Checking ... +String OK. +Length OK. + +Trying lb1 ... +Checking ... +String OK. +Length OK. + +Trying lb2 ... +Checking ... +String OK. +Length OK. + +Trying lb3 ... +Checking ... +String OK. +Length OK. + +Trying lb4 ... +Checking ... +String OK. +Length OK. + +Trying lb5 ... +java.lang.IllegalArgumentException: removing negative number (-1) of elements +Checking ... +String OK. +Length OK. + diff --git a/test/files/run/t6634.scala b/test/files/run/t6634.scala new file mode 100644 index 0000000000..759e6d519d --- /dev/null +++ b/test/files/run/t6634.scala @@ -0,0 +1,80 @@ +import collection.mutable.ListBuffer + +object Test extends App { + def newLB = ListBuffer('a, 'b, 'c, 'd, 'e) + + val lb0 = newLB + println("Trying lb0 ...") + try { + lb0.remove(5, 0) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb0) + + val lb1 = newLB + println("Trying lb1 ...") + try { + lb1.remove(6, 6) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb1) + + val lb2 = newLB + println("Trying lb2 ...") + try { + lb2.remove(99, 6) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb2) + + val lb3 = newLB + println("Trying lb3 ...") + try { + lb3.remove(1, 9) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IllegalArgumentException => println(ex) + } + checkNotCorrupted(lb3, "ListBuffer('a)", 1) + + val lb4 = newLB + println("Trying lb4 ...") + try { + lb4.remove(-1, 1) + } catch { + // Not thrown in 2.10, will be thrown in 2.11 + case ex: IndexOutOfBoundsException => println(ex) + } + checkNotCorrupted(lb4, "ListBuffer('b, 'c, 'd, 'e)", 4) + + val lb5 = newLB + println("Trying lb5 ...") + try { + lb5.remove(1, -1) + } catch { + case ex: IllegalArgumentException => println(ex) + } + checkNotCorrupted(lb5) + + // buffer should neither be changed nor corrupted after calling remove with invalid arguments + def checkNotCorrupted( + lb: ListBuffer[Symbol], + expectedString: String = "ListBuffer('a, 'b, 'c, 'd, 'e)", + expectedLength: Int = 5) = { + println("Checking ...") + val replStr = scala.runtime.ScalaRunTime.replStringOf(lb, 100) + if (replStr == expectedString + "\n") println("String OK.") + else println("!!! replStringOf FAILED: " + replStr) + + val len = lb.length + if (len == expectedLength) println("Length OK.") + else println("!!! length FAILED: " + len) + println() + } +}
\ No newline at end of file diff --git a/test/files/run/t6663.check b/test/files/run/t6663.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/t6663.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/t6663.scala b/test/files/run/t6663.scala new file mode 100644 index 0000000000..6818d286d9 --- /dev/null +++ b/test/files/run/t6663.scala @@ -0,0 +1,17 @@ +import language.dynamics + +class C(v: Any) extends Dynamic { + def selectDynamic[T](n: String): Option[T] = Option(v.asInstanceOf[T]) + def applyDynamic[T](n: String)(): Option[T] = Option(v.asInstanceOf[T]) +} + +object Test extends App { + // this should be converted to + // C(42).selectDynamic[Int]("foo").get + // but, before fixing SI-6663, became + // C(42).selectDynamic[Nothing]("foo").get + // leading to a ClassCastException + var v = new C(42).foo[Int].get + println(v) +} + diff --git a/test/files/run/t6673.check b/test/files/run/t6673.check new file mode 100644 index 0000000000..ef2aa551dc --- /dev/null +++ b/test/files/run/t6673.check @@ -0,0 +1 @@ +List(x) diff --git a/test/files/run/t6673.scala b/test/files/run/t6673.scala new file mode 100644 index 0000000000..115bbdf234 --- /dev/null +++ b/test/files/run/t6673.scala @@ -0,0 +1,5 @@ +object Test extends App { + def foo(f: String => Array[String])(s: String) = f(s) + val test = foo(Array(_)) _ + println(test("x").toList) +}
\ No newline at end of file diff --git a/test/files/run/t6695.scala b/test/files/run/t6695.scala new file mode 100644 index 0000000000..b527238a51 --- /dev/null +++ b/test/files/run/t6695.scala @@ -0,0 +1,18 @@ +object Test extends App { + try { + Array("a", "b", "c") match { + case Array("a", "x", "c") => println("x") + case Array("a", "b", "x") => println("a"); + case Array("a", "d", _*) => println("wrongly positive") + } + assert(false, "match succeeded") + } catch { + case _: MatchError => // okay + } + + Array("a", "b", "c") match { + case Array("a", "x", "c") => println("x") + case Array("a", "b", "x") => println("a"); + case Array("a", "b", _*) => // okay + } +} diff --git a/test/files/run/t6706.scala b/test/files/run/t6706.scala new file mode 100644 index 0000000000..905494ca8d --- /dev/null +++ b/test/files/run/t6706.scala @@ -0,0 +1,14 @@ +object Test { + var name = "foo" + 1 + var s1 = Symbol(name) + s1 = null + System.gc + val s2 = Symbol("foo1") + name = null + System.gc + val s3 = Symbol("foo1") + + def main(args: Array[String]): Unit = { + assert(s2 eq s3, ((s2, System.identityHashCode(s2), s3, System.identityHashCode(s3)))) + } +} |