Skip to content

Commit bae7965

Browse files
committed
Add tests related to variance checking.
1 parent 035aff4 commit bae7965

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/neg/Variances.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait HasY { type Y }
2+
3+
// These are neg-tests corresponding to the pos-test Variances.scala
4+
// where all the variance annotations have been inverted.
5+
trait Foo1[+X] { def bar[Y <: X](y: Y) = y } // error
6+
trait Foo2[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
7+
trait Foo3[-X] { def bar[Y >: X](y: Y) = y } // error
8+
trait Foo4[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
9+
10+
// These are neg-tests corresponding to the pos-test Variances.scala
11+
// where all the bounds have been flipped.
12+
trait Foo5[-X] { def bar[Y >: X](y: Y) = y } // error
13+
trait Foo6[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
14+
trait Foo7[+X] { def bar[Y <: X](y: Y) = y } // error
15+
trait Foo8[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error

tests/pos/Variances.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait HasY { type Y }
2+
3+
// This works in scalac.
4+
trait Foo1[-X] { def bar[Y <: X](y: Y) = y }
5+
6+
// A variant of the Foo1 using a dependent method type (doesn't work
7+
// using scalac)
8+
trait Foo2[-X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y }
9+
10+
// This works in scalac.
11+
trait Foo3[+X] { def bar[Y >: X](y: Y) = y }
12+
13+
// A variant of the Foo4 using a dependent method type (doesn't work
14+
// using scalac)
15+
trait Foo4[+X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y }

0 commit comments

Comments
 (0)