aboutsummaryrefslogtreecommitdiff
path: root/tests/pickling/typers.scala
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/typers.scala
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/typers.scala')
-rw-r--r--tests/pickling/typers.scala153
1 files changed, 153 insertions, 0 deletions
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
+ }
+
+
+}