Skip to content
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

variance validation is buggy #7536

Open
scabug opened this issue May 30, 2013 · 6 comments
Open

variance validation is buggy #7536

scabug opened this issue May 30, 2013 · 6 comments
Milestone

Comments

@scabug
Copy link

scabug commented May 30, 2013

I'm going to fix this.

trait Base[A]

trait Ord1[-A] extends Base[A1 forSome { type A1 >: A }]  // fails
trait Ord2[-A, A1 >: A] extends Base[A1]                  // compiles

trait Ord3[+A] extends Base[A1 forSome { type A1 <: A }]  // fails
trait Ord4[+A, A1 <: A] extends Base[A1]                  // compiles
a.scala:3: error: contravariant type A occurs in invariant position in type [-A]Base[A1 forSome { type A1 >: A }] of trait Ord1
trait Ord1[-A] extends Base[A1 forSome { type A1 >: A }]  // fails
      ^
a.scala:6: error: covariant type A occurs in invariant position in type [+A]Base[A1 forSome { type A1 <: A }] of trait Ord3
trait Ord3[+A] extends Base[A1 forSome { type A1 <: A }]  // fails
      ^
two errors found
@scabug
Copy link
Author

scabug commented May 30, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7536?orig=1
Reporter: @paulp
See #7872

@scabug
Copy link
Author

scabug commented Nov 22, 2013

@paulp said:
I'm unlikely to fix this, but here's a test case.

trait Base[A]

// SHOULD FAIL
trait Neg1[-A] extends Base[A1 forSome { type A1 <: A }]
trait Neg2[-A, A1 <: A] extends Base[A1]
trait Neg3[+A] extends Base[A1 forSome { type A1 >: A }]
trait Neg4[+A, A1 >: A] extends Base[A1]

// SHOULD COMPILE
trait Pos1[-A] extends Base[A1 forSome { type A1 >: A }]
trait Pos2[-A, A1 >: A] extends Base[A1]
trait Pos3[+A] extends Base[A1 forSome { type A1 <: A }]
trait Pos4[+A, A1 <: A] extends Base[A1]

// a.scala:4: error: contravariant type A occurs in invariant position in type [-A]Base[A1 forSome { type A1 <: A }] of trait Neg1
//   --- should be "in covariant position"
// a.scala:6: error: covariant type A occurs in invariant position in type [+A]Base[A1 forSome { type A1 >: A }] of trait Neg3
//   --- should be "in contravariant position"
// a.scala:10: error: contravariant type A occurs in invariant position in type [-A]Base[A1 forSome { type A1 >: A }] of trait Pos1
//   --- should compile
// a.scala:12: error: covariant type A occurs in invariant position in type [+A]Base[A1 forSome { type A1 <: A }] of trait Pos3
//   --- should compile

@scabug
Copy link
Author

scabug commented Nov 22, 2013

@retronym said:
I wonder if this will fall out of my patch for #7872.

@SethTisue
Copy link
Member

reopen if still applicable in current Scala

@eparejatobes
Copy link

For the test case above #7536 (comment) in 2.12.4 we have

  1. all NegX fail to compile
  2. Pos1 and Pos3 fail to compile

See https://scastie.scala-lang.org/KH0We1NnSAGqLKUaZ8IrHg.

PS why closing and then checking if it's been fixed?

@lrytz lrytz added this to the Backlog milestone Mar 2, 2018
@lrytz lrytz reopened this Mar 2, 2018
@SethTisue
Copy link
Member

SethTisue commented Mar 2, 2018

why closing and then checking if it's been fixed?

because it isn't good for the health of the bug tracker to have an overwhelming number of open tickets, many of which are years old and of questionable value. it creates a vicious circle where nobody looks at the tickets because there are too many, and there are too many because nobody looks at them.

there are so many we've strongly considered declaring bug bankruptcy and just closing them all. instead, taking a milder approach where we don't just blindly assume every ticket, no matter how old, must be valid.

because we need volunteers to confirm which ones are still relevant

because reopening is easy when something found to still be relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants