aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/typers.scala
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pos/typers.scala')
-rw-r--r--tests/pos/typers.scala84
1 files changed, 43 insertions, 41 deletions
diff --git a/tests/pos/typers.scala b/tests/pos/typers.scala
index cb3bbc590..4f012e7bf 100644
--- a/tests/pos/typers.scala
+++ b/tests/pos/typers.scala
@@ -1,61 +1,61 @@
-package test
+package test
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 :: (x: T) = 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 {
@@ -70,69 +70,71 @@ object typers {
val y = try 2 catch Predef.identity
val z = try 3 finally "abc"
-
+
println("abc".toString)
}
class C {
-
+
@tailrec 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 {
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(self: Int) { 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)
}
@@ -145,6 +147,6 @@ object typers {
}
val yy: String = y
}
-
-} \ No newline at end of file
+
+}