Skip to content

Commit db24466

Browse files
committed
Merge pull request #1193 from dotty-staging/fix-variances
merge variances and Variances
2 parents 5bd08d4 + 3a27571 commit db24466

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

test/dotc/tests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class tests extends CompilerTest {
5555
val dotcDir = toolsDir + "dotc/"
5656
val coreDir = dotcDir + "core/"
5757
val parsingDir = dotcDir + "parsing/"
58-
val replDir = dotcDir + "repl/"
58+
val dottyReplDir = dotcDir + "repl/"
5959
val typerDir = dotcDir + "typer/"
6060

6161
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
@@ -254,7 +254,7 @@ class tests extends CompilerTest {
254254
@Test def tasty_dotc_repl = compileList("tasty_dotc_repl", List(
255255
"AbstractFileClassLoader.scala", "ConsoleWriter.scala", "InteractiveReader.scala",
256256
"Interpreter.scala", "Main.scala", "NewLinePrintWriter.scala", "REPL.scala", "SimpleReader.scala"
257-
) map (replDir + _), testPickling)
257+
) map (dottyReplDir + _), testPickling)
258258

259259
//@Test def tasty_dotc_reporting = compileDir(dotcDir, "reporting", testPickling)
260260
@Test def tasty_dotc_rewrite = compileDir(dotcDir, "rewrite", testPickling)

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)