diff options
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/List1.scala | 4 | ||||
-rw-r--r-- | test/files/pos/exceptions.scala | 5 | ||||
-rw-r--r-- | test/files/pos/expressions-current.scala | 63 | ||||
-rw-r--r-- | test/files/pos/patterns3.scala | 5 | ||||
-rw-r--r-- | test/files/pos/philippe4.scala | 3 | ||||
-rw-r--r-- | test/files/pos/simplelists.scala | 17 |
6 files changed, 93 insertions, 4 deletions
diff --git a/test/files/pos/List1.scala b/test/files/pos/List1.scala index 6c54f109ce..f0fce9501f 100644 --- a/test/files/pos/List1.scala +++ b/test/files/pos/List1.scala @@ -9,8 +9,8 @@ object lists { def Nil[a] = new List[a] { def isEmpty: Boolean = true; - def head = error[a]("head of Nil"); - def tail = error[List[a]]("tail of Nil"); + def head = error("head of Nil"); + def tail = error("tail of Nil"); } def Cons[a](x: a, xs: List[a]): List[a] = new List[a] { diff --git a/test/files/pos/exceptions.scala b/test/files/pos/exceptions.scala index 7c376f3aac..c47b0e4785 100644 --- a/test/files/pos/exceptions.scala +++ b/test/files/pos/exceptions.scala @@ -7,7 +7,8 @@ object test { def main(): Unit = { try { try { - error("hi!"); + System.out.println("hi!"); + error("xx"); } finally { System.out.println("ho!") } @@ -18,4 +19,4 @@ object test { } main(); -}
\ No newline at end of file +} diff --git a/test/files/pos/expressions-current.scala b/test/files/pos/expressions-current.scala new file mode 100644 index 0000000000..207adb2b14 --- /dev/null +++ b/test/files/pos/expressions-current.scala @@ -0,0 +1,63 @@ +package test; + +abstract class Lang { + trait Visitor { + def caseNum(n: int): unit; + } + + abstract class Exp { + def visit(v: visitor): unit; + } + + type visitor <: Visitor; + + class Num(n: int) extends Exp { + def visit(v: visitor): unit = v.caseNum(n); + } + + class Eval(result: Ref[int]): visitor extends Visitor { + def caseNum(n: int) = result.elem = n; + } +} + +abstract class Lang2 extends Lang { + trait Visitor2 extends Visitor { + def casePlus(left: Exp, right: Exp): unit; + } + + type visitor <: Visitor2; + + class Plus(l: Exp, r: Exp) extends Exp { + def visit(v: visitor): unit = v.casePlus(l, r); + } + + class Eval2(result: Ref[int]): visitor extends Eval(result) with Visitor2 { + def casePlus(l: Exp, r: Exp) = + result.elem = { l.visit(this); result.elem } + { r.visit(this); result.elem } + } + + class Show2(result: Ref[String]): visitor extends Visitor2 { + def caseNum(n: int) = result.elem = n.toString(); + def casePlus(l: Exp, r: Exp) = + result.elem = + "(" + { l.visit(this); result.elem } + + "+" + { r.visit(this); result.elem }+ ")"; + } +} + +object Main { + + def main(args: Array[String]) = { + val l1 = new Lang { type visitor = Visitor } + val e1: l1.Exp = new l1.Num(42); + + val iref = new Ref(0); + System.out.println("eval: " + { e1.visit(new l1.Eval(iref)); iref.elem }); + + val l2 = new Lang2 { type visitor = Visitor2 } + val e2: l2.Exp = new l2.Plus(new l2.Num(5), new l2.Num(37)); + val sref = new Ref(""); + System.out.println("eval: " + { e2.visit(new l2.Eval2(iref)); iref.elem }); + System.out.println("show: " + { e2.visit(new l2.Show2(sref)); sref.elem }); + } +} diff --git a/test/files/pos/patterns3.scala b/test/files/pos/patterns3.scala new file mode 100644 index 0000000000..6caa834852 --- /dev/null +++ b/test/files/pos/patterns3.scala @@ -0,0 +1,5 @@ +module M { + + val Tuple2(Tuple2(x, y), _) = Tuple2(Tuple2(1, 2), 3); + +}
\ No newline at end of file diff --git a/test/files/pos/philippe4.scala b/test/files/pos/philippe4.scala new file mode 100644 index 0000000000..c9b1cdaeb0 --- /dev/null +++ b/test/files/pos/philippe4.scala @@ -0,0 +1,3 @@ +trait Foo[t <: Foo[t]]: t { + def foo(that: t): Boolean; +} diff --git a/test/files/pos/simplelists.scala b/test/files/pos/simplelists.scala new file mode 100644 index 0000000000..143bbdd77b --- /dev/null +++ b/test/files/pos/simplelists.scala @@ -0,0 +1,17 @@ + abstract class List[+a] { + def head: a; + def tail: List[a]; + def cons[b >: a](x: b): List[b] = new Cons[b, a](x, this); + } + + object Nil extends List[All] { + def error(msg: String): All = new java.lang.Error(msg).throw; + def head: All = error("Nil.head"); + def tail: List[All] = error("Nil.tail"); + } + + class Cons[c, d <: c](x: c, xs: List[d]) extends List[c] { + def head: c = x; + def tail: List[c] = xs; + } + |