From 901fc77f387acd9598859de03a1386a236fe0b1b Mon Sep 17 00:00:00 2001 From: Sandro Stucki Date: Tue, 29 Mar 2016 18:29:36 +0200 Subject: [PATCH] Add tests related to variance checking. --- tests/neg/Variances.scala | 15 +++++++++++++++ tests/pos/Variances.scala | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/neg/Variances.scala create mode 100644 tests/pos/Variances.scala diff --git a/tests/neg/Variances.scala b/tests/neg/Variances.scala new file mode 100644 index 000000000000..0ceb64452cfa --- /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 000000000000..5c448ec88aa2 --- /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 }