Skip to content

Commit 7871236

Browse files
committed
merge variances and Variances
1 parent 5bd08d4 commit 7871236

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
@@ -41,4 +41,19 @@ object Test2 extends App {
4141
}
4242

4343

44+
trait HasY { type Y }
45+
46+
// These are neg-tests corresponding to the pos-test Variances.scala
47+
// where all the variance annotations have been inverted.
48+
trait Foo1[+X] { def bar[Y <: X](y: Y) = y } // error
49+
trait Foo2[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
50+
trait Foo3[-X] { def bar[Y >: X](y: Y) = y } // error
51+
trait Foo4[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
52+
53+
// These are neg-tests corresponding to the pos-test Variances.scala
54+
// where all the bounds have been flipped.
55+
trait Foo5[-X] { def bar[Y >: X](y: Y) = y } // error
56+
trait Foo6[-X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y } // error
57+
trait Foo7[+X] { def bar[Y <: X](y: Y) = y } // error
58+
trait Foo8[+X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y } // error
4459

tests/pos/variances.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
trait C[+T <: C[T, U], -U <: C[T, U]] {
22

33
}
4+
trait HasY { type Y }
5+
6+
// This works in scalac.
7+
trait Foo1[-X] { def bar[Y <: X](y: Y) = y }
8+
9+
// A variant of Foo1 using a dependent method type (doesn't work using
10+
// scalac)
11+
trait Foo2[-X] { def bar(x: HasY { type Y <: X })(y: x.Y) = y }
12+
13+
// This works in scalac.
14+
trait Foo3[+X] { def bar[Y >: X](y: Y) = y }
15+
16+
// A variant of Foo3 using a dependent method type (doesn't work
17+
// using scalac)
18+
trait Foo4[+X] { def bar(x: HasY { type Y >: X })(y: x.Y) = y }

0 commit comments

Comments
 (0)