aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSandro Stucki <sandro.stucki@gmail.com>2016-03-29 18:29:36 +0200
committerSandro Stucki <sandro.stucki@gmail.com>2016-03-30 14:57:34 +0200
commit901fc77f387acd9598859de03a1386a236fe0b1b (patch)
tree1434354d1c75d5a11afdffa1f93f0d29d49f5274 /tests
parent035aff45e89084290b8f67ca49007c3eac00f13f (diff)
downloaddotty-901fc77f387acd9598859de03a1386a236fe0b1b.tar.gz
dotty-901fc77f387acd9598859de03a1386a236fe0b1b.tar.bz2
dotty-901fc77f387acd9598859de03a1386a236fe0b1b.zip
Add tests related to variance checking.
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/Variances.scala15
-rw-r--r--tests/pos/Variances.scala15
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/neg/Variances.scala b/tests/neg/Variances.scala
new file mode 100644
index 000000000..0ceb64452
--- /dev/null
+++ b/tests/neg/Variances.scala
@@ -0,0 +1,15 @@
+trait HasY { type Y }
+
+// These are neg-tests corresponding to the pos-test Variances.scala
+// where all the variance annotations have been inverted.
+trait Foo1[+X] { def bar[Y <: X](y: Y) = y } // error
+trait Foo2[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
+trait Foo3[-X] { def bar[Y >: X](y: Y) = y } // error
+trait Foo4[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
+
+// These are neg-tests corresponding to the pos-test Variances.scala
+// where all the bounds have been flipped.
+trait Foo5[-X] { def bar[Y >: X](y: Y) = y } // error
+trait Foo6[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
+trait Foo7[+X] { def bar[Y <: X](y: Y) = y } // error
+trait Foo8[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
diff --git a/tests/pos/Variances.scala b/tests/pos/Variances.scala
new file mode 100644
index 000000000..5c448ec88
--- /dev/null
+++ b/tests/pos/Variances.scala
@@ -0,0 +1,15 @@
+trait HasY { type Y }
+
+// This works in scalac.
+trait Foo1[-X] { def bar[Y <: X](y: Y) = y }
+
+// A variant of Foo1 using a dependent method type (doesn't work using
+// scalac)
+trait Foo2[-X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y }
+
+// This works in scalac.
+trait Foo3[+X] { def bar[Y >: X](y: Y) = y }
+
+// A variant of Foo3 using a dependent method type (doesn't work
+// using scalac)
+trait Foo4[+X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y }