Skip to content

Add tests related to variance checking. #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/neg/Variances.scala
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/pos/Variances.scala
Original file line number Diff line number Diff line change
@@ -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 }