From 225fac5af513f7bc7edd7b7e8e262ab151ef823e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 15 Jun 2007 18:00:19 +0000 Subject: more existentials --- test/files/neg/bug409.check | 2 +- test/files/neg/bug593.check | 2 +- test/files/neg/sabin2.check | 5 ++++ test/files/neg/sabin2.scala | 23 +++++++++++++++++++ test/files/run/existentials.check | 3 +++ test/files/run/existentials.scala | 48 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/sabin2.check create mode 100644 test/files/neg/sabin2.scala create mode 100644 test/files/run/existentials.check create mode 100755 test/files/run/existentials.scala (limited to 'test/files') diff --git a/test/files/neg/bug409.check b/test/files/neg/bug409.check index 63ece3b0f0..25e5a41d16 100644 --- a/test/files/neg/bug409.check +++ b/test/files/neg/bug409.check @@ -1,4 +1,4 @@ -bug409.scala:6: error: traits may not have parameters +bug409.scala:6: error: traits or objects may not have parameters class Toto extends Expr with Case1(12); ^ one error found diff --git a/test/files/neg/bug593.check b/test/files/neg/bug593.check index eeb745631b..f71affec5a 100644 --- a/test/files/neg/bug593.check +++ b/test/files/neg/bug593.check @@ -1,4 +1,4 @@ -bug593.scala:1: error: traits may not have parameters +bug593.scala:1: error: traits or objects may not have parameters trait Wrapper[T](x : T) { ^ one error found diff --git a/test/files/neg/sabin2.check b/test/files/neg/sabin2.check new file mode 100644 index 0000000000..e127cc67a2 --- /dev/null +++ b/test/files/neg/sabin2.check @@ -0,0 +1,5 @@ +sabin2.scala:22: error: method set cannot be accessed in Test.this.Base#Inner + because its instance type (Test.this.Base#T)Unit contains a malformed type: Test.this.Base#T + a.set(b.get()) // Error + ^ +one error found diff --git a/test/files/neg/sabin2.scala b/test/files/neg/sabin2.scala new file mode 100644 index 0000000000..308632e990 --- /dev/null +++ b/test/files/neg/sabin2.scala @@ -0,0 +1,23 @@ +object Test extends Application + { + abstract class Base { + type T + var x: T = _ + class Inner { + def set(y: T) = x = y + def get() = x + def print() = println("Hello world") + } + } + + object IntBase extends Base { type T = Int } + object StringBase extends Base { type T = String } + + val a : Base#Inner = new IntBase.Inner + val b : Base#Inner = new StringBase.Inner + + a.print() // OK + b.print() // OK + + a.set(b.get()) // Error + } 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 +} -- cgit v1.2.3