diff options
author | Martin Odersky <odersky@gmail.com> | 2012-04-05 17:17:39 -0700 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2012-04-05 17:17:39 -0700 |
commit | 115f5467e3f3ff07abbba2b23c40c2ff0d7ddd1b (patch) | |
tree | 15265c311900918c79c5eda8d54c58fc145ef4a8 /test/files/neg/variances.scala | |
parent | 7f79ef0e30f088b41b14763f44338c240acf1a63 (diff) | |
parent | 754b4a85e4093f25cc10f092fefdb34215097c94 (diff) | |
download | scala-115f5467e3f3ff07abbba2b23c40c2ff0d7ddd1b.tar.gz scala-115f5467e3f3ff07abbba2b23c40c2ff0d7ddd1b.tar.bz2 scala-115f5467e3f3ff07abbba2b23c40c2ff0d7ddd1b.zip |
Merge branch 'master' into topic/reflect
Diffstat (limited to 'test/files/neg/variances.scala')
-rw-r--r-- | test/files/neg/variances.scala | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/test/files/neg/variances.scala b/test/files/neg/variances.scala index 726bc35270..10ca111cd0 100644 --- a/test/files/neg/variances.scala +++ b/test/files/neg/variances.scala @@ -1,7 +1,7 @@ package test trait Vector[+A] { - def append(x: Vector[A]): Vector[A] + def append(x: Vector[A]): Vector[A] private[this] def append3(x: Vector[A]): Vector[A] = append(x) } @@ -11,19 +11,27 @@ object Covariant { class Foo[+A] { private[this] var a : A = _ def getA : A = a - private[this] def setA(a : A) = this.a = a - + // allowed + private[this] def setA1(a : A) = this.a = a + protected[this] def setA2(a : A) = this.a = a + // forbidden + private def setA3(a : A) = this.a = a + protected def setA4(a : A) = this.a = a + object Baz extends C[A] trait Convert[B] { def b2a(b : B) : A - def doit(b : B) = setA(b2a(b)) + def doit1(b : B) = setA1(b2a(b)) + def doit2(b : B) = setA2(b2a(b)) + def doit3(b : B) = setA3(b2a(b)) + def doit4(b : B) = setA4(b2a(b)) } } class Foo2[+A] { private[this] var a : A = _ def getA : A = a - private[this] def setA(a : A) = this.a = a - + private[this] def setA(a : A) = this.a = a + { trait Convert[B] { def b2a(b : B) : A @@ -35,8 +43,8 @@ object Covariant { class Foo3[+A] { private[this] var a : A = _ def getA : A = a - private[this] def setA(a : A) = this.a = a - + private[this] def setA(a : A) = this.a = a + private[this] trait Convert[B] { def b2a(b : B) : A def doit(b : B) = setA(b2a(b)) @@ -54,7 +62,10 @@ object Covariant { } def main(args : Array[String]) { val test = new Test - test.c.doit(test.b) + test.c.doit1(test.b) + test.c.doit2(test.b) + test.c.doit3(test.b) + test.c.doit4(test.b) val x : java.lang.Character = test.a.getA Console.println("XXX " + x) } |