summaryrefslogtreecommitdiff
path: root/test/files/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-07-20 19:12:30 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-07-23 09:39:11 +0200
commit5c5e8d4dcd151a6e2bf9e7c259c618b9b4eff00f (patch)
treebe08a99fb120ab98e09f090ba4d3ec48e6049e8a /test/files/pos
parent7b62eeea86c62f5e068c366065f8f4c2e6624eb7 (diff)
downloadscala-5c5e8d4dcd151a6e2bf9e7c259c618b9b4eff00f.tar.gz
scala-5c5e8d4dcd151a6e2bf9e7c259c618b9b4eff00f.tar.bz2
scala-5c5e8d4dcd151a6e2bf9e7c259c618b9b4eff00f.zip
SI-4881 infer variance from formals, then result
Changed behavior so that when determining the target variance of a method parameter, the variance in formals comes first. If variance is still undecided by that, the variance in the result type is used as a secondary criterion. (This is also done when determining prototype type params.)
Diffstat (limited to 'test/files/pos')
-rw-r--r--test/files/pos/t4881.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/pos/t4881.scala b/test/files/pos/t4881.scala
new file mode 100644
index 0000000000..46cfad9793
--- /dev/null
+++ b/test/files/pos/t4881.scala
@@ -0,0 +1,31 @@
+class Contra[-T]
+trait A
+trait B extends A
+trait C extends B
+
+// test improved variance inference: first try formals to see in which variance positions the type param appears;
+// only when that fails to determine variance, look at result type
+object Test {
+ def contraLBUB[a >: C <: A](): Contra[a] = null
+ def contraLB[a >: C](): Contra[a] = null
+
+{
+ val x = contraLBUB() //inferred Contra[C] instead of Contra[A]
+ val x1: Contra[A] = x
+}
+
+{
+ val x = contraLB() //inferred Contra[C] instead of Contra[Any]
+ val x1: Contra[Any] = x
+}
+
+{
+ val x = contraLBUB // make sure it does the same thing as its ()-less counterpart
+ val x1: Contra[A] = x
+}
+
+{
+ val x = contraLB
+ val x1: Contra[Any] = x
+}
+}