aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-01-27 12:46:48 +0100
committerMartin Odersky <odersky@gmail.com>2015-02-07 17:31:53 +0100
commit1f8b5691dabaae336c3c3f568b303eb24e783494 (patch)
tree7546b2148b5863e2e0070122ffc6d67eacf9edf4 /tests/pos
parent4320e20ff5f3126940f0ecad1dd53573cf03562b (diff)
downloaddotty-1f8b5691dabaae336c3c3f568b303eb24e783494.tar.gz
dotty-1f8b5691dabaae336c3c3f568b303eb24e783494.tar.bz2
dotty-1f8b5691dabaae336c3c3f568b303eb24e783494.zip
Test reorg
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/sammy_poly.scala7
-rw-r--r--tests/pos/scoping1.scala12
-rw-r--r--tests/pos/sealed-final.scala14
-rw-r--r--tests/pos/spec-sealed.scala32
-rw-r--r--tests/pos/subtyping.scala29
-rw-r--r--tests/pos/t319.scala22
-rw-r--r--tests/pos/t3278.scala30
-rw-r--r--tests/pos/t3343.scala15
-rw-r--r--tests/pos/t3411.scala8
-rw-r--r--tests/pos/t344.scala12
10 files changed, 153 insertions, 28 deletions
diff --git a/tests/pos/sammy_poly.scala b/tests/pos/sammy_poly.scala
new file mode 100644
index 000000000..f43fa292c
--- /dev/null
+++ b/tests/pos/sammy_poly.scala
@@ -0,0 +1,7 @@
+// test synthesizeSAMFunction where the sam type is not fully defined
+class T {
+ trait F[T, U] { def apply(x: T): U }
+ // NOTE: the f(x) desugaring for now assumes the single abstract method is called 'apply'
+ def app[T, U](x: T)(f: F[T, U]): U = f(x)
+ app(1)(x => List(x))
+}
diff --git a/tests/pos/scoping1.scala b/tests/pos/scoping1.scala
new file mode 100644
index 000000000..83ad1357a
--- /dev/null
+++ b/tests/pos/scoping1.scala
@@ -0,0 +1,12 @@
+object This extends App {
+ trait A {
+ def foo(): Unit
+ }
+ abstract class C { self: A =>
+ def bar() = this.foo()
+ }
+ class D extends C with A {
+ def foo() = ()
+ }
+ val c: C = new D
+}
diff --git a/tests/pos/sealed-final.scala b/tests/pos/sealed-final.scala
new file mode 100644
index 000000000..bdedb5c1f
--- /dev/null
+++ b/tests/pos/sealed-final.scala
@@ -0,0 +1,14 @@
+sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+}
+object Foo {
+ def mkFoo(): Foo = new Baz2
+}
+
+object Baz1 extends Foo
+final class Baz2 extends Foo
+
+object Test {
+ // bar should be inlined now
+ def f = Foo.mkFoo() bar 10
+}
diff --git a/tests/pos/spec-sealed.scala b/tests/pos/spec-sealed.scala
new file mode 100644
index 000000000..d7ecfaaab
--- /dev/null
+++ b/tests/pos/spec-sealed.scala
@@ -0,0 +1,32 @@
+sealed abstract class MyList[@specialized +A] {
+ def head: A
+ def tail: MyList[A]
+
+ def ::[@specialized B >: A](x: B): MyList[B] =
+ new Cons[B](x, this)
+}
+
+case object MyNil extends MyList[Nothing] {
+ def head = sys.error("nil")
+ def tail = sys.error("nil")
+}
+
+case class Cons[@specialized a](private val hd: a, tl: MyList[a]) extends MyList[a] {
+ def head = hd
+ def tail = tl
+}
+
+abstract class IntList extends MyList[Int]
+
+object Main extends App {
+ val xs = 1 :: 2 :: 3 :: MyNil
+ println(xs)
+}
+
+/*
+final class ConsI(hd1: Int, tl1: MyList[Int]) extends Cons[Int](hd1, tl1) {
+ override val hd = hd1
+ override val tl = tl1
+}
+*/
+//class IntCons(_hd: Int, _tl: MyList[Int]) extends Cons[Int](_hd, _tl)
diff --git a/tests/pos/subtyping.scala b/tests/pos/subtyping.scala
index 29d830dd2..e65bdd16f 100644
--- a/tests/pos/subtyping.scala
+++ b/tests/pos/subtyping.scala
@@ -1,32 +1,5 @@
-class A {
- def test1(): Unit = {
- implicitly[this.type <:< this.type]
- implicitly[this.type <:< A]
- }
-}
object test {
- def tag1[T](x: T): String & T = ???
- def tag2[T](x: T): T & String = ???
-
- val x1: Int & String = tag1(0)
- val x2: Int & String = tag2(0)
- val x3: String & Int = tag1(0)
- val x4: String & Int = tag2(0)
-
-}
-
-object test2 {
-
- class A
- class B
-
- val x: A | B = ???
- val y: B | A = x
-
- val a: A & B = ???
- val b: B & A = a
+ val x: Int = 1
}
-
-
diff --git a/tests/pos/t319.scala b/tests/pos/t319.scala
new file mode 100644
index 000000000..5c06f4db0
--- /dev/null
+++ b/tests/pos/t319.scala
@@ -0,0 +1,22 @@
+object test {
+
+ trait A { type T; }
+
+ trait B { type T; }
+
+ /** def functor(x: A): B { type T = x.T } */
+ abstract class functor() {
+ val arg: A;
+ val res: B { type T = arg.T } =
+ new B { type T = arg.T; };
+ }
+
+ val a = new A { type T = String };
+ /** val b: B { type T = String } = functor(a) */
+ val b: B { type T = String } = {
+ val tmp = new functor() { val arg: A { type T = String } = a };
+ // Dotty deviaton: arg needs an explicit type here, or else the inherited type `A` would be assumed.
+ tmp.res
+ }
+
+}
diff --git a/tests/pos/t3278.scala b/tests/pos/t3278.scala
new file mode 100644
index 000000000..05bfbc146
--- /dev/null
+++ b/tests/pos/t3278.scala
@@ -0,0 +1,30 @@
+class Foo
+class Test {
+ def update[B](x : B, b : Int): Unit = {}
+ def apply[B](x : B) = 1
+}
+class Test2 {
+ type B = Foo
+ def update(x : B, b : Int): Unit = {}
+ def apply(x : B) = 1
+}
+
+object Test {
+ def main(a : Array[String]): Unit = {
+ val a = new Test
+ val f = new Foo
+ a(f) = 1 //works
+ a(f) = a(f) + 1 //works
+ a(f) += 1 //error: reassignment to val
+ }
+}
+object Test2 {
+ def main(args : Array[String]): Unit = {
+ args(0) += "a"
+ val a = new Test2
+ val f = new Foo
+ a(f) = 1 //works
+ a(f) = a(f) + 1 //works
+ a(f) += 1 //error: reassignment to val
+ }
+}
diff --git a/tests/pos/t3343.scala b/tests/pos/t3343.scala
new file mode 100644
index 000000000..9d1bc9355
--- /dev/null
+++ b/tests/pos/t3343.scala
@@ -0,0 +1,15 @@
+import scala.collection.mutable.{ Builder, ListBuffer }
+
+object Test {
+ class Converter[T]
+ object SimpleIntConverter extends Converter[Int]
+
+ class TraversableConverter[T, Coll[X] <: Traversable[X]](converter: Converter[T], builder: Builder[T, Coll[T]]) extends Converter[Coll[T]] {
+ def convert(x: T): List[T] = List(x)
+ }
+ val tc: Converter[List[Int]] = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int])
+ val tc2 = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int])
+
+ def main(args: Array[String]): Unit = {
+ }
+}
diff --git a/tests/pos/t3411.scala b/tests/pos/t3411.scala
new file mode 100644
index 000000000..6d46be4e4
--- /dev/null
+++ b/tests/pos/t3411.scala
@@ -0,0 +1,8 @@
+object A {
+ def g(c: PartialFunction[Any,Unit]): Unit = {}
+
+ def f: Unit = {
+ lazy val x = 0
+ g { case `x` => }
+ }
+}
diff --git a/tests/pos/t344.scala b/tests/pos/t344.scala
new file mode 100644
index 000000000..449a763af
--- /dev/null
+++ b/tests/pos/t344.scala
@@ -0,0 +1,12 @@
+object Bug {
+ class A;
+ case class A1() extends A;
+ case class A2() extends A;
+ def f: A =
+ if (true)
+ A1()
+ else {
+ val a = if (true) A1() else A2();
+ a
+ };
+}