diff options
author | Martin Odersky <odersky@gmail.com> | 2015-03-05 13:22:00 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:14:15 +0100 |
commit | 321563940dee1716c19600efd57acb9ed83a7687 (patch) | |
tree | 9053dfcff007d16ceb6dbaa7256889455a7a07a7 /tests/pos | |
parent | 7fd242f2f1b1d2f536e73ec0fdb92a34b27b2a89 (diff) | |
download | dotty-321563940dee1716c19600efd57acb9ed83a7687.tar.gz dotty-321563940dee1716c19600efd57acb9ed83a7687.tar.bz2 dotty-321563940dee1716c19600efd57acb9ed83a7687.zip |
Compute PureInterface flag after pickling.
ElimLocals becomes a slightly less trivial transform: NormalizeFlags.
It also computes PureInterface flag, thus relieving Namer and Unpickler
from doing the same in two different ways. Besides, the computation in
Namer/TreeInfo was flawed because it did not take into account that
nested non-static classes are not allowed in an interface (only static
classes are, but these would not be members of the interface in the Scala
sense).
Diffstat (limited to 'tests/pos')
-rw-r--r-- | tests/pos/pickleOK/Labels.scala | 21 | ||||
-rw-r--r-- | tests/pos/pickleOK/arrays2.scala | 32 | ||||
-rw-r--r-- | tests/pos/pickleOK/desugar.scala | 88 | ||||
-rw-r--r-- | tests/pos/pickleOK/i94-nada.scala | 45 | ||||
-rw-r--r-- | tests/pos/pickleOK/partialApplications.scala | 13 | ||||
-rw-r--r-- | tests/pos/pickleOK/traits.scala | 27 | ||||
-rw-r--r-- | tests/pos/pickleOK/tryTyping.scala | 20 | ||||
-rw-r--r-- | tests/pos/pickleOK/typers.scala | 153 |
8 files changed, 399 insertions, 0 deletions
diff --git a/tests/pos/pickleOK/Labels.scala b/tests/pos/pickleOK/Labels.scala new file mode 100644 index 000000000..4a84175af --- /dev/null +++ b/tests/pos/pickleOK/Labels.scala @@ -0,0 +1,21 @@ +object Labels { + def main(args: Array[String]): Unit = { + var i = 10 + while(i>0) { + var j = 0 + while(j<i) { + println(j+" " + i) + j = j +1 + } + i = i - 1} + pattern(1) + pattern(2) + pattern(3) + } + + def pattern(a: Int) = a match { + case 1 if (a>0) => println("one") + case t@2 => println("two" + t) + case _ => println("default") + } +} diff --git a/tests/pos/pickleOK/arrays2.scala b/tests/pos/pickleOK/arrays2.scala new file mode 100644 index 000000000..1a0d3e660 --- /dev/null +++ b/tests/pos/pickleOK/arrays2.scala @@ -0,0 +1,32 @@ +package arrays + +case class C(); + +object arrays2 { + + def main(args: Array[String]): Unit = { + val a: Array[Array[C]] = new Array[Array[C]](2); + a(0) = new Array[C](2); + a(0)(0) = new C(); + } +} + +// #2422 +object arrays4 { + val args = Array[String]("World") + "Hello %1$s".format(args: _*) +} + +// #2461 +object arrays3 { + import scala.collection.JavaConversions._ + def apply[X](xs : X*) : java.util.List[X] = java.util.Arrays.asList(xs: _*) + + def apply1[X <: String](xs : X*) : java.util.List[X] = java.util.Arrays.asList(xs: _*) + def apply2[X <: AnyVal](xs : X*) : java.util.List[X] = java.util.Arrays.asList(xs: _*) + def apply3(xs : Int*) : java.util.List[Int] = java.util.Arrays.asList(xs: _*) + def apply4(xs : Unit*) : java.util.List[Unit] = java.util.Arrays.asList(xs: _*) + def apply5(xs : Null*) : java.util.List[Null] = java.util.Arrays.asList(xs: _*) + def apply6(xs : Nothing*) : java.util.List[Nothing] = java.util.Arrays.asList(xs: _*) +} + diff --git a/tests/pos/pickleOK/desugar.scala b/tests/pos/pickleOK/desugar.scala new file mode 100644 index 000000000..0d3b6d8ca --- /dev/null +++ b/tests/pos/pickleOK/desugar.scala @@ -0,0 +1,88 @@ +object desugar { + + // variables + var x: Int = 2 + var y = x * x + val list = List(1, 2, 3) + + { var z: Int = y } + + def foo0(first: Int, second: Int = 2, third: Int = 3) = first + second + def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second + def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second + + object caseClasses { self => + trait List[+T] { + def head: T + def tail: List[T] + } + + case class Cons[+T](val head: T, val tail: List[T]) extends List[T] + + object Cons { + def apply[T](head: T): Cons[T] = apply(head, Nil) + } + + case object Nil extends List[Nothing] { + def head = throw new Error() + def tail = throw new Error() + } + } + + object patDefs { + + import caseClasses._ + + val xs: List[Int] = Cons(1, Cons(2, Nil)) + + val Cons(y, ys) = xs + val Cons(z, _) = xs + val Cons(_, _) = xs + + val (cons: Cons[Int]) = xs + + val x1, y1, z1: Int = 1 + } + + object Binops { + + x :: y :: Nil + + val x :: y :: Nil = list + + } + + object fors { + + for (x <- List(1, 2, 3)) yield 2 + for (x <- List(1, 2, 3) if x % 2 == 0) yield x * x + for (x <- List(1, 2, 3); y <- 0 to x) yield x * y + for (x <- List(1, 2, 3); y <- 0 to x; if x + y % 2 == 0) yield x * y + for (x <- List(1, 2, 3); y = x * x; if x + y % 2 == 0) yield x * y + for (x <- List(1, 2, 3); y = x * x; z = x * y; u <- 0 to y) yield x * y * z * u + + for (x <- List(1, 2, 3)) println(x) + for (x <- List(1, 2, 3) if x % 2 == 0) println(x * x) + for (x <- List(1, 2, 3); y <- 0 to x) println(x * y) + for (x <- List(1, 2, 3); y <- 0 to x; if x + y % 2 == 0) println(x * y) + for (x <- List(1, 2, 3); y = x * x; if x + y % 2 == 0) println(x * y) + for (x <- List(1, 2, 3); y = x * x; z = x * y; u <- 0 to y) println(x * y * z * u) + } + + object misc { + 'hello + s"this is a $x + ${x + y} string" + type ~ = Tuple2 + val pair: Int ~ String = 1 -> "abc" + def foo(xs: Int*) = xs.length + foo(list: _*) + println(list: _*) + (list length) + - desugar.x + def bar(x: => Int) = x + (x + y) + 1 + while (x < 10) x += 1 + do x -= 1 while (x > 0) + } + +} diff --git a/tests/pos/pickleOK/i94-nada.scala b/tests/pos/pickleOK/i94-nada.scala new file mode 100644 index 000000000..ce8dc98ad --- /dev/null +++ b/tests/pos/pickleOK/i94-nada.scala @@ -0,0 +1,45 @@ +package i94 + +import scala.language.higherKinds + +trait Base { + type Rep[T] +} + +trait BaseExp extends Base { + type Rep[T] = Exp[T] + case class Exp[T](v: T) +} + +trait BaseStr extends Base { + type Rep[T] = String +} + +trait BaseDirect extends Base { + type Rep[T] = T +} + +trait Test1 { + trait Monad[X] { + def x: X + } + sealed abstract class Either[A,B] + case class Left[A,B](x: A) extends Either[A,B] with Monad[A] + case class Right[A,B](x: B) extends Either[A,B] with Monad[B] + def flatMap[X,Y,M[X]<:Monad[X]](m: M[X], f: X => M[Y]): M[Y] = f(m.x) + println(flatMap(Left(1), {x: Int => Left(x)})) +} +trait Test2 { + trait Monad[X] { + def x: X + } + sealed abstract class Either[A,B] + case class Left[A,B](x: A) extends Either[A,B] with Monad[A] + case class Right[A,B](x: B) extends Either[A,B] with Monad[B] + def flatMap[X,Y,M[X]](m: M[X], f: X => M[Y]): M[Y] + println(flatMap(Left(1), {x: Int => Left(x)})) +} +trait Test3 { + def flatMap[X,Y,M[X]](m: M[X], f: X => M[Y]): M[Y] + println(flatMap(Some(1), {x: Int => Some(x)})) +} diff --git a/tests/pos/pickleOK/partialApplications.scala b/tests/pos/pickleOK/partialApplications.scala new file mode 100644 index 000000000..f517011b9 --- /dev/null +++ b/tests/pos/pickleOK/partialApplications.scala @@ -0,0 +1,13 @@ +object PartialApplications { + + type Histogram = Map[_, Int] + + type StringlyHistogram = Histogram[_ >: String] + + val xs: Histogram[String] = Map[String, Int]() + + val ys: StringlyHistogram[String] = xs + + val zs: StringlyHistogram = xs + +} diff --git a/tests/pos/pickleOK/traits.scala b/tests/pos/pickleOK/traits.scala new file mode 100644 index 000000000..e93ebc46b --- /dev/null +++ b/tests/pos/pickleOK/traits.scala @@ -0,0 +1,27 @@ +package traits + +trait B extends Object { + + val z: Int + +} + +trait T extends B { + + var x = 2 + + private var xp = 2 + + val y = 3 + + private val yp = 3 + + val z = 4 + + x = 4 + + xp = 4 + +} + +class C extends T diff --git a/tests/pos/pickleOK/tryTyping.scala b/tests/pos/pickleOK/tryTyping.scala new file mode 100644 index 000000000..a2aeb17c8 --- /dev/null +++ b/tests/pos/pickleOK/tryTyping.scala @@ -0,0 +1,20 @@ +object tryTyping{ + def foo: Int = { + try{???; 1} + catch { + case e: Exception => 2 + } + } + + def foo2: Int = { + val a2: (Throwable => Int) = _ match {case _ => 2} + try{???; 1} + catch a2 + } + + def foo3: Int = { + val a3: (Int => Throwable => Int) = (b: Int) => _ match {case _ => b} + try{???; 1} + catch a3(3) + } +}
\ No newline at end of file diff --git a/tests/pos/pickleOK/typers.scala b/tests/pos/pickleOK/typers.scala new file mode 100644 index 000000000..56007729e --- /dev/null +++ b/tests/pos/pickleOK/typers.scala @@ -0,0 +1,153 @@ +package typers + +import annotation.{tailrec, switch} +import collection.mutable._ + +object typers { + + val names = List("a", "b", "c") + val ints = List(1, 2, 3) + + object Inference { + + for ((name, n) <- (names, ints).zipped) + println(name.length + n) + + def double(x: Char): String = s"$x$x" + + "abc" flatMap double + + } + object Eta { + + def fun(x: Int): Int = x + 1 + val foo = fun(_) + } + + case class DefaultParams(init: String => String = identity) + object DefaultParams { + def foo(x: String => String = identity) = x("abc") + + foo() + } + + class List[+T] { + def :: [U >: T](x: U): List[U] = new :: (x, this) + + def len: Int = this match { + case x :: xs1 => 1 + xs1.len + case Nil => 0 + } + } + + object Nil extends List[Nothing] + + case class :: [+T] (hd: T, tl: List[T]) extends List[T] + + def len[U](xs: List[U]): Int = xs match { + case x :: xs1 => 1 + len(xs1) + case Nil => 0 + } + + object returns { + + def foo(x: Int): Int = { + return 3 + } + } + + object tries { + + val x = try { + "abc" + } catch { + case ex: java.io.IOException => + 123 + } finally { + println("done") + } + + val y = try 2 catch Predef.identity + + val z = try 3 finally "abc" + + println("abc".toString) + + } + + class C { + + @tailrec final def factorial(acc: Int, n: Int): Int = (n: @switch) match { + case 0 => acc + case _ => factorial(acc * n, n - 1) + } + + println(factorial(1, 10)) + + + } + + class Refinements { + trait C { type T; def process(x: T): Int } + val y: C { type T; val key: T; def process(x: T): Int } = ??? + } + + object Accessibility { + + class A { + val x: String = "abc" + } + + class B extends A { + private def x: Int = 1 + } + + val b: B = new B + val y = b.x + val z: String = y + + } + + object Self { + + class A(self1: Int) { self => + + def self1(x: Int) = x + + class B { + val b = self + val c: A = b + } + + val a = self + val c: A = a + } + + + } + + object Arrays { + + val arr = List("a", "b", "c").toArray + val i = 2 + arr(i).charAt(0) + + val x = new ArrayBuffer[String] // testing overloaded polymorphic constructors + + val entries = Array("abc", "def") + + for ((x, i) <- entries.zipWithIndex) + println(x) + } + + object SeqExtractors { + val y = names match { + case List(x, z) => x + case List(x) => x + case List() => "" + } + val yy: String = y + } + + +} |