aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-10-07 14:23:38 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-12 10:50:57 +0200
commitfd81127c6255d01237dd98e8296abf6fdfe80741 (patch)
treec9c6f2f6f17173fb5539c57022f68274e495a281 /tests/pos
parentfa44d5cd694d76e285ebadcdf297f0d13936a6e9 (diff)
downloaddotty-fd81127c6255d01237dd98e8296abf6fdfe80741.tar.gz
dotty-fd81127c6255d01237dd98e8296abf6fdfe80741.tar.bz2
dotty-fd81127c6255d01237dd98e8296abf6fdfe80741.zip
New tests
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/array-clone.scala7
-rw-r--r--tests/pos/getset.scala23
-rw-r--r--tests/pos/lambdalift.scala46
-rw-r--r--tests/pos/points.scala8
-rw-r--r--tests/pos/synthetics.scala4
-rw-r--r--tests/pos/t7093.scala27
-rw-r--r--tests/pos/unapply.scala11
7 files changed, 126 insertions, 0 deletions
diff --git a/tests/pos/array-clone.scala b/tests/pos/array-clone.scala
new file mode 100644
index 000000000..ef5ac5c85
--- /dev/null
+++ b/tests/pos/array-clone.scala
@@ -0,0 +1,7 @@
+object test {
+
+ val xs = Array(1, 2, 3)
+
+ val ys: Array[Int] = xs.clone()
+
+}
diff --git a/tests/pos/getset.scala b/tests/pos/getset.scala
new file mode 100644
index 000000000..7b6207e94
--- /dev/null
+++ b/tests/pos/getset.scala
@@ -0,0 +1,23 @@
+package test
+
+trait T {
+
+ val x = 2
+
+ var y = 2
+
+ private[this] var z = 3
+
+ private var a = 3
+
+}
+class C {
+
+ val x = 2
+
+ var y = 2
+
+ private[this] var z = 3
+
+ private var a = 3
+}
diff --git a/tests/pos/lambdalift.scala b/tests/pos/lambdalift.scala
new file mode 100644
index 000000000..febae6828
--- /dev/null
+++ b/tests/pos/lambdalift.scala
@@ -0,0 +1,46 @@
+object test {
+
+ def foo(x: Int) = {
+
+ def bar(y: Int) = x + y
+ def baz(z: Int) = bar(z)
+
+ baz(1)
+
+ }
+
+ def foo2(x: Int) = {
+
+ class C {
+ def bam(y: Int): String => Int = {
+ def baz = x + y
+ z => baz * z.length
+ }
+ }
+
+ val fun = new C().bam(1)
+ fun("abc")
+
+ }
+}
+
+class Super(x: Int)
+
+class Sub extends Super({
+ def foo3(x: Int) = {
+
+ class C {
+ def this(name: String) = this()
+
+ def bam(y: Int): String => Int = {
+ def baz = x + y
+ z => baz * z.length
+ }
+ }
+
+ val fun = new C("dummy").bam(1)
+ fun("abc")
+
+ }
+ foo3(22)
+})
diff --git a/tests/pos/points.scala b/tests/pos/points.scala
new file mode 100644
index 000000000..db6104c88
--- /dev/null
+++ b/tests/pos/points.scala
@@ -0,0 +1,8 @@
+class Point extends Comparable[Point] {
+ override def compareTo(other: Point): Int = ???
+}
+
+class ColoredPoint extends Point with Comparable[ColoredPoint] {
+ override def compareTo(other: ColoredPoint): Int = ???
+}
+
diff --git a/tests/pos/synthetics.scala b/tests/pos/synthetics.scala
new file mode 100644
index 000000000..c7d49df70
--- /dev/null
+++ b/tests/pos/synthetics.scala
@@ -0,0 +1,4 @@
+case class C(x: Int, var y: String) {
+
+}
+
diff --git a/tests/pos/t7093.scala b/tests/pos/t7093.scala
new file mode 100644
index 000000000..287b7a78c
--- /dev/null
+++ b/tests/pos/t7093.scala
@@ -0,0 +1,27 @@
+object Test {
+
+ trait A[+X] {
+ protected[this] def f(x: X): X = x
+ }
+
+ trait B extends A[B] {
+ def kaboom = f(new B {})
+ }
+
+// protected[this] disables variance checking
+// of the signature of `f`.
+//
+// C's parent list unifies A[B] with A[C]
+//
+// The protected[this] loophole is widely used
+// in the collections, every newBuilder method
+// would fail variance checking otherwise.
+ class C extends B with A[C] {
+ override protected[this] def f(c: C) = c
+ }
+
+// java.lang.ClassCastException: B$$anon$1 cannot be cast to C
+// at C.f(<console>:15)
+ new C().kaboom
+}
+
diff --git a/tests/pos/unapply.scala b/tests/pos/unapply.scala
new file mode 100644
index 000000000..ba885be73
--- /dev/null
+++ b/tests/pos/unapply.scala
@@ -0,0 +1,11 @@
+object test {
+ class Foo[T](val arg : T)
+
+ object Foo {
+ def unapply [a](m : Foo[a]) = Some (m.arg)
+ }
+ def matchAndGetArgFromFoo[b]( e:Foo[b]):b = {e match { case Foo(x) => x }}
+// Unapply node here will have type argument [a] instantiated to scala.Nothing:
+// UnApply(TypeApply(Select(Ident(Foo),unapply),List(TypeTree[TypeVar(PolyParam(a) -> TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing))])),List(),List(Bind(x,Ident(_))))
+// but the type of the UnApply node itself is correct: RefinedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),test$)),Foo), test$$Foo$$a, TypeAlias(TypeRef(NoPrefix,a)))
+}