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

trait encoding introduces variance error #4345

Closed
scabug opened this issue Mar 16, 2011 · 3 comments
Closed

trait encoding introduces variance error #4345

scabug opened this issue Mar 16, 2011 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Mar 16, 2011

Clearly there is a bug here, but I don't know whether the bug is that both should compile or that neither should. If protected[this] is supposed to turn off variance checks like private[this] does, I don't see it in the spec. So I'm supposing neither should compile.

The following fails with a variance error:

trait C1[+A, +CC[X]] {
  protected[this] def f: A => CC[A] = sys.error("")
}

trait C2[+A, +CC[X]] extends C1[A, CC] {
  override protected[this] def f = super.f
}
// bug.scala:6: error: covariant type A occurs in contravariant position in type => (A) => CC[A] of method super$$f
//   override protected[this] def f = super.f
//                                          ^
// one error found

If we change C2 to a class, it compiles.

trait C1[+A, +CC[X]] {
  protected[this] def f: A => CC[A] = sys.error("")
}

class C2[+A, +CC[X]] extends C1[A, CC] {
  override protected[this] def f = super.f
}
@scabug
Copy link
Author

scabug commented Mar 16, 2011

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

@scabug
Copy link
Author

scabug commented Mar 22, 2011

@ingoem said:
Maybe related to #3272.

@scabug
Copy link
Author

scabug commented Mar 22, 2011

@adriaanm said:
(In r24539) closes #4345. skip variance checks for calls to super accessor. no review

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

No branches or pull requests

2 participants