aboutsummaryrefslogtreecommitdiff
path: root/tests/pickling
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-03-08 22:02:22 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-03-18 11:16:37 +0100
commit5962a931c83622ce065bc1ce9add049ade89bfcf (patch)
tree24851bbc76f1ca537456715c44a9f866a5c00668 /tests/pickling
parent19bfc0c6c9be9c4c3fdca55480e01e980a493b42 (diff)
downloaddotty-5962a931c83622ce065bc1ce9add049ade89bfcf.tar.gz
dotty-5962a931c83622ce065bc1ce9add049ade89bfcf.tar.bz2
dotty-5962a931c83622ce065bc1ce9add049ade89bfcf.zip
Pickling test reorg
Move pickling tests into separate top-level test directory. That way they are not needlessly pos-tested before. Also, disable core tests for now - after rebasing we get a stale symbol error. Need to investigate that.
Diffstat (limited to 'tests/pickling')
-rw-r--r--tests/pickling/Coder.scala59
-rw-r--r--tests/pickling/Labels.scala21
-rw-r--r--tests/pickling/alias.scala3
-rw-r--r--tests/pickling/arrays2.scala32
-rw-r--r--tests/pickling/desugar.scala88
-rw-r--r--tests/pickling/extmethods.scala8
-rw-r--r--tests/pickling/hk.scala56
-rw-r--r--tests/pickling/i94-nada.scala45
-rw-r--r--tests/pickling/nameddefaults.scala63
-rw-r--r--tests/pickling/new-array.scala17
-rw-r--r--tests/pickling/partialApplications.scala13
-rw-r--r--tests/pickling/selftypes.scala20
-rw-r--r--tests/pickling/t1957.scala65
-rw-r--r--tests/pickling/templateParents.scala25
-rw-r--r--tests/pickling/traits.scala27
-rw-r--r--tests/pickling/tryTyping.scala20
-rw-r--r--tests/pickling/typers.scala153
-rw-r--r--tests/pickling/unapply.scala11
-rw-r--r--tests/pickling/unions.scala33
-rw-r--r--tests/pickling/varargs.scala13
-rw-r--r--tests/pickling/zoo.scala41
21 files changed, 813 insertions, 0 deletions
diff --git a/tests/pickling/Coder.scala b/tests/pickling/Coder.scala
new file mode 100644
index 000000000..77bbd134c
--- /dev/null
+++ b/tests/pickling/Coder.scala
@@ -0,0 +1,59 @@
+import collection.mutable.HashMap
+
+class Coder(words: List[String]) {
+
+ (2 -> "ABC", new ArrowAssoc('3') -> "DEF")
+
+ private val mnemonics = Map(
+ '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
+ '6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
+
+
+ ('1', "1") match {
+ case (digit, str) => true
+ case _ => false
+ }
+
+ /** Invert the mnemonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
+ private val charCode0: Map[Char, Char] = mnemonics withFilter {
+ case (digit, str) => true
+ case _ => false
+ } flatMap { x$1 =>
+ x$1 match {
+ case (digit, str) => str map (ltr => ltr -> digit)
+ }
+ }
+
+ private val charCode: Map[Char, Char] =
+ for ((digit, str) <- mnemonics; ltr <- str) yield ltr -> digit
+
+ /** Maps a word to the digit string it can represent */
+ private def wordCode(word: String): String = word map charCode
+
+ /** A map from digit strings to the words that represent them */
+ private val wordsForNum: Map[String, List[String]] =
+ words groupBy wordCode withDefaultValue Nil
+
+ /** All ways to encode a number as a list of words */
+ def encode(number: String): Set[List[String]] =
+ if (number.isEmpty) Set(Nil)
+ else {
+ for {
+ splitPoint <- 1 to number.length
+ word <- wordsForNum(number take splitPoint)
+ rest <- encode(number drop splitPoint)
+ } yield word :: rest
+ }.toSet
+
+ /** Maps a number to a list of all word phrases that can represent it */
+ def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
+
+}
+
+object Coder {
+ def main(args : Array[String]) : Unit = {
+ val coder = new Coder(List("Scala", "sobls", "Python", "Ruby", "C", "A", "rocks", "sucks", "works", "Racka"))
+// println(coder.wordsForNum)
+ println(coder.translate("7225276257"))
+ }
+}
diff --git a/tests/pickling/Labels.scala b/tests/pickling/Labels.scala
new file mode 100644
index 000000000..4a84175af
--- /dev/null
+++ b/tests/pickling/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/pickling/alias.scala b/tests/pickling/alias.scala
new file mode 100644
index 000000000..a66edc73a
--- /dev/null
+++ b/tests/pickling/alias.scala
@@ -0,0 +1,3 @@
+class A(val x: Int)
+
+class B(x: Int) extends A(x)
diff --git a/tests/pickling/arrays2.scala b/tests/pickling/arrays2.scala
new file mode 100644
index 000000000..1a0d3e660
--- /dev/null
+++ b/tests/pickling/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/pickling/desugar.scala b/tests/pickling/desugar.scala
new file mode 100644
index 000000000..0d3b6d8ca
--- /dev/null
+++ b/tests/pickling/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/pickling/extmethods.scala b/tests/pickling/extmethods.scala
new file mode 100644
index 000000000..1cbc9f2ee
--- /dev/null
+++ b/tests/pickling/extmethods.scala
@@ -0,0 +1,8 @@
+package extMethods
+
+trait That1[A]
+class T[A, This <: That1[A]](val x: Int) extends AnyVal {
+ self: This =>
+ var next: This = _
+ final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1)
+}
diff --git a/tests/pickling/hk.scala b/tests/pickling/hk.scala
new file mode 100644
index 000000000..9fdaf94f6
--- /dev/null
+++ b/tests/pickling/hk.scala
@@ -0,0 +1,56 @@
+import language.higherKinds
+
+object hk0 {
+
+ abstract class Base {
+ type Rep[T]
+ val strRep: Rep[String]
+ }
+
+ class Sub extends Base {
+ type Rep[T] = T
+ val strRep = "abc"
+ val sr: Rep[String] = ""
+ }
+
+ abstract class Functor[F[_]] {
+ def map[A, B](f: A => B): F[A] => F[B]
+ }
+ val ml: Functor[List] = ???
+ val mx = ml
+ val mm: (Int => Boolean) => List[Int] => List[Boolean] = mx.map
+}
+
+object higherKinded {
+
+ type Untyped = Null
+
+ class Tree[-T >: Untyped] {
+ type ThisType[-U >: Untyped] <: Tree[U]
+ def withString(s: String): ThisType[String] = withString(s)
+ }
+
+ class Ident[-T >: Untyped] extends Tree[T] {
+ type ThisType[-U] = Ident[U]
+ }
+
+ val id = new Ident[Integer]
+
+ val y = id.withString("abc")
+
+ val z: Ident[String] = y
+
+ val zz: tpd.Tree = y
+
+ abstract class Instance[T >: Untyped] {
+ type Tree = higherKinded.Tree[T]
+ }
+
+ object tpd extends Instance[String]
+
+ def transform(tree: Tree[String]) = {
+ val tree1 = tree.withString("")
+ tree1: Tree[String]
+ }
+
+}
diff --git a/tests/pickling/i94-nada.scala b/tests/pickling/i94-nada.scala
new file mode 100644
index 000000000..ce8dc98ad
--- /dev/null
+++ b/tests/pickling/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/pickling/nameddefaults.scala b/tests/pickling/nameddefaults.scala
new file mode 100644
index 000000000..671f14a07
--- /dev/null
+++ b/tests/pickling/nameddefaults.scala
@@ -0,0 +1,63 @@
+object nameddefaults {
+
+ def foo(first: Int, second: Int = 2, third: Int = 3) = first + second
+
+ var x = 1
+ var y = 2
+
+ foo(1, 2, 3)
+
+ foo(1, 2)
+
+ foo(1)
+
+ // named and missing arguments
+
+ foo(first = 1, second = 3)
+
+ foo(second = 3, first = 1)
+
+ foo(first = 2, third = 3)
+
+ foo(2, third = 3)
+
+ // same but with non-idempotent expressions
+
+ foo(first = x, second = y)
+
+ foo(second = x, first = y)
+
+ foo(first = x, third = y)
+
+ foo(x, third = y)
+
+// The same thing, but for classes
+
+ class C(first: Int, second: Int = 2, third: Int = 3) {}
+
+ new C(1, 2, 3)
+
+ new C(1, 2)
+
+ new C(1)
+
+ // named and missing arguments
+
+ new C(first = 1, second = 3)
+
+ new C(second = 3, first = 1)
+
+ new C(first = 2, third = 3)
+
+ new C(2, third = 3)
+
+ // same but with non-idempotent expressions
+
+ new C(first = x, second = y)
+
+ new C(second = x, first = y)
+
+ new C(first = x, third = y)
+
+
+}
diff --git a/tests/pickling/new-array.scala b/tests/pickling/new-array.scala
new file mode 100644
index 000000000..a323783de
--- /dev/null
+++ b/tests/pickling/new-array.scala
@@ -0,0 +1,17 @@
+package newArray
+
+object Test {
+ val w = new Array[String](10)
+ val x = new Array[Int](10)
+ def f[T: reflect.ClassTag] = new Array[T](10)
+ val y = new Array[Any](10)
+ val z = new Array[Unit](10)
+}
+object Test2 {
+ val w: Array[Any] = new Array(10)
+ val x: Array[Int] = new Array(10)
+ def f[T: reflect.ClassTag]: Array[T] = new Array(10)
+ val y: Array[Any] = new Array(10)
+ val z: Array[Unit] = new Array(10)
+}
+
diff --git a/tests/pickling/partialApplications.scala b/tests/pickling/partialApplications.scala
new file mode 100644
index 000000000..f517011b9
--- /dev/null
+++ b/tests/pickling/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/pickling/selftypes.scala b/tests/pickling/selftypes.scala
new file mode 100644
index 000000000..243405f77
--- /dev/null
+++ b/tests/pickling/selftypes.scala
@@ -0,0 +1,20 @@
+object selftypes {
+
+ trait A { self: AB =>
+
+ type AA = List[this.BX]
+
+ class AX
+
+ }
+
+ trait B { self: AB =>
+
+ type BB = AA
+
+ class BX
+ }
+
+ class AB extends A with B
+
+} \ No newline at end of file
diff --git a/tests/pickling/t1957.scala b/tests/pickling/t1957.scala
new file mode 100644
index 000000000..5fcc1723b
--- /dev/null
+++ b/tests/pickling/t1957.scala
@@ -0,0 +1,65 @@
+package t1957
+
+// See comment at end of file.
+object Test {
+ abstract class Settings {}
+
+ abstract class Grist
+ { self =>
+ type settingsType <: Settings
+ type moduleType <: Module {type settingsType = self.settingsType}
+ val module: moduleType
+ }
+
+ abstract class Tool
+ { self =>
+ type settingsType <: Settings
+ type moduleType = Module { type settingsType = self.settingsType }
+ type gristType = Grist { type moduleType <: self.moduleType; type settingsType <: self.settingsType }
+
+ def inputGrist: List[gristType]
+ }
+
+ abstract class Module
+ { self =>
+ type settingsType <: Settings
+ final type commonModuleType = Module {type settingsType = self.settingsType}
+ type selfType >: self.type <: commonModuleType
+
+ // BTW: if we use the commented out type decls, the code compiles successfully
+ // type gristType = Grist {type settingsType <: self.settingsType; type moduleType <: commonModuleType }
+
+ val tools: List[Tool {type settingsType = self.settingsType}]
+
+ protected def f: List[commonModuleType] =
+ {
+ val inputGrists = tools.flatMap(_.inputGrist)
+ // This produces an unhygienic closure for _.inputGrist.
+ // Pickling will log:
+ //
+ // [...] pickling reference to as yet undefined value _$1 in method $anonfun
+ //
+ // More info can be produced by uncommenting these two lines in
+ // Namer#valOrDefDefSig:
+ //
+ //println(i"lifting $rhsType over $paramss -> $hygienicType = ${tpt.tpe}")
+ //println(TypeComparer.explained { implicit ctx => hygienicType <:< tpt.tpe })
+ //
+ // Tracing the subtype statement (over 1600+ lines!) shows that the TypeComparer thinks that the
+ // following subtype judgement is true:
+ //
+ // Test.Grist{
+ // moduleType <: Test.Module{settingsType = Module.this.settingsType};
+ // settingsType <: Module.this.settingsType
+ // } <:< Test.Grist{moduleType <: _$1.moduleType; settingsType <: _$1.settingsType}
+ //
+ // Therefore, a type variable which has the second type as lower bound does not get
+ // the (hygienic) first type as new lower bound. Clearly something is wrong in the subtype
+ // derivation here. It would be important to figure out what.
+
+ ???
+// inputGrists.map(_.module)
+ }
+
+ }
+}
diff --git a/tests/pickling/templateParents.scala b/tests/pickling/templateParents.scala
new file mode 100644
index 000000000..153c4b4da
--- /dev/null
+++ b/tests/pickling/templateParents.scala
@@ -0,0 +1,25 @@
+object templateParents {
+
+ // traits do not call a constructor
+ class C[+T](val x: T)
+ trait D extends C[String]
+ trait E extends C[Int]
+ class F extends C[Boolean](true) {
+ def foo = x
+ }
+ val cd = new C("abc") with D
+ cd.x
+
+}
+
+object templateParents1 {
+ // tests inference of synthesized class type
+ class C[+T]
+ trait D extends C[String]
+ trait E extends C[Int]
+
+ val x = new D with E
+
+ val y: C[Int & String] = x
+}
+
diff --git a/tests/pickling/traits.scala b/tests/pickling/traits.scala
new file mode 100644
index 000000000..e93ebc46b
--- /dev/null
+++ b/tests/pickling/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/pickling/tryTyping.scala b/tests/pickling/tryTyping.scala
new file mode 100644
index 000000000..a2aeb17c8
--- /dev/null
+++ b/tests/pickling/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/pickling/typers.scala b/tests/pickling/typers.scala
new file mode 100644
index 000000000..56007729e
--- /dev/null
+++ b/tests/pickling/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
+ }
+
+
+}
diff --git a/tests/pickling/unapply.scala b/tests/pickling/unapply.scala
new file mode 100644
index 000000000..ba885be73
--- /dev/null
+++ b/tests/pickling/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)))
+}
diff --git a/tests/pickling/unions.scala b/tests/pickling/unions.scala
new file mode 100644
index 000000000..22e6391e3
--- /dev/null
+++ b/tests/pickling/unions.scala
@@ -0,0 +1,33 @@
+object unions {
+
+ class A {
+ def f: String = "abc"
+
+ def g(x: Int): Int = x
+ def g(x: Double): Double = x
+ }
+
+ class B {
+ def f: String = "bcd"
+
+ def g(x: Int) = -x
+ def g(x: Double): Double = -x
+ }
+
+ val x: A | B = if (true) new A else new B
+ def y: B | A = if (true) new A else new B
+ println(x.f)
+ println(x.g(2))
+ println(y.f)
+ println(y.g(1.0))
+ println(y.g(1.0f))
+
+ class C {
+ private def foo = 0
+ class D extends C {
+ private def foo = 1
+ def test(cd: C | D, dc: D | C) = (cd.foo, dc.foo)
+ }
+ }
+
+}
diff --git a/tests/pickling/varargs.scala b/tests/pickling/varargs.scala
new file mode 100644
index 000000000..3739636b8
--- /dev/null
+++ b/tests/pickling/varargs.scala
@@ -0,0 +1,13 @@
+object varargs {
+ List(1, 2, 3)
+ def g(x: Int*) = x.length
+ g(1, 2, 3, 4)
+ val x = if (true) 1 else 2
+ def foo[T](x: T, y: T): T = x
+ foo(1, 2)
+ val xs = 1 :: 2 :: Nil
+ g(xs: _*)
+ g(Nil: _*)
+ g(1)
+ g()
+} \ No newline at end of file
diff --git a/tests/pickling/zoo.scala b/tests/pickling/zoo.scala
new file mode 100644
index 000000000..02dac8f5b
--- /dev/null
+++ b/tests/pickling/zoo.scala
@@ -0,0 +1,41 @@
+object Test {
+trait FoodStuff
+trait Meat extends FoodStuff {
+ type IsMeat = Any
+}
+trait Grass extends FoodStuff {
+ type IsGrass = Any
+}
+trait Animal {
+ type Food <: FoodStuff
+ def eats(food: Food): Unit
+ def gets: Food
+}
+trait Cow extends Animal {
+ type IsMeat = Any
+ type Food <: Grass
+ def eats(food: Grass): Unit
+ def gets: Food
+}
+trait Lion extends Animal {
+ type Food = Meat
+ def eats(food: Meat): Unit
+ def gets: Meat
+}
+def newMeat: Meat = new Meat {
+}
+def newGrass: Grass = new Grass {
+}
+def newCow: Cow = new Cow {
+ type Food = Grass
+ def eats(food: Grass) = ()
+ def gets = newGrass
+}
+def newLion: Lion = new Lion {
+ def eats(food: Meat) = ()
+ def gets = newMeat
+}
+val milka = newCow
+val leo = newLion
+//leo.eats(milka) // structural select not supported
+}