diff options
author | Martin Odersky <odersky@gmail.com> | 2007-06-15 18:00:19 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-06-15 18:00:19 +0000 |
commit | 225fac5af513f7bc7edd7b7e8e262ab151ef823e (patch) | |
tree | 06bf7b50cd2486323994fe32999bdc2754c37cac /test/files/run | |
parent | ba3b4ba405c66059a3ca7809557d988358fa7162 (diff) | |
download | scala-225fac5af513f7bc7edd7b7e8e262ab151ef823e.tar.gz scala-225fac5af513f7bc7edd7b7e8e262ab151ef823e.tar.bz2 scala-225fac5af513f7bc7edd7b7e8e262ab151ef823e.zip |
more existentials
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/existentials.check | 3 | ||||
-rwxr-xr-x | test/files/run/existentials.scala | 48 |
2 files changed, 51 insertions, 0 deletions
diff --git a/test/files/run/existentials.check b/test/files/run/existentials.check new file mode 100644 index 0000000000..c1bffda530 --- /dev/null +++ b/test/files/run/existentials.check @@ -0,0 +1,3 @@ +Int 2 +Float 2 +Cell(abc) diff --git a/test/files/run/existentials.scala b/test/files/run/existentials.scala new file mode 100755 index 0000000000..3d51751996 --- /dev/null +++ b/test/files/run/existentials.scala @@ -0,0 +1,48 @@ +class Foo { + class Line { + case class Cell[T](var x: T) + def f[T](x: Any): Cell[t1] for_some { type t1 } = x match { case y: Cell[t] => y } + + var x: Cell[T] for_some { type T } = new Cell(1) + println({ x = new Cell("abc"); x }) + } +} + +trait Counter[T] { + def newCounter: T + def get(i: T): Int + def inc(i: T): T + } + + object Test extends Application { + + def foo(x : Counter[T] { def name : String } for_some { type T }) = x match { + case ctr: Counter[t] => + val c = ctr.newCounter + println(ctr.name+" "+ctr.get(ctr.inc(ctr.inc(c)))) + case _ => + } + + var ex: Counter[T] for_some { type T } = _ + ex = ci + ex = cf + + val ci = new Counter[Int] { + def newCounter = 0 + def get(i: Int) = i + def inc(i: Int) = i+1 + def name = "Int" + } + + val cf = new Counter[Float] { + def newCounter = 0 + def get(i: Float) = i.intValue + def inc(i: Float) = i+1 + def name = "Float" + } + + foo(ci) + foo(cf) + val foo = new Foo + new foo.Line +} |