Skip to content

Unsoundness due to missing variance checks for extends clause #2973

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

Closed
smarter opened this issue Aug 14, 2017 · 4 comments · Fixed by #4932
Closed

Unsoundness due to missing variance checks for extends clause #2973

smarter opened this issue Aug 14, 2017 · 4 comments · Fixed by #4932

Comments

@smarter
Copy link
Member

smarter commented Aug 14, 2017

This shouldn't compile:

class Foo[T]
class Bar[-T] extends Foo[T]

scalac realises that:

error: contravariant type T occurs in invariant position in type [-T]Foo[T] {
  def <init>(): Bar[T]
} of class Bar
class Bar[-T] extends Foo[T]
      ^
one error found
@TomasMikula
Copy link
Contributor

In #3856 I argue that this should compile, and the other way, i.e.

class Foo[-T]
class Bar[T] extends Foo[T]

shouldn't.

@Blaisorblade Blaisorblade changed the title Missing variance checks for extends clause Unsoundness due to missing variance checks for extends clause Mar 1, 2018
@Blaisorblade
Copy link
Contributor

@TomasMikula Added some comments on your idea; TLDR I agree with @smarter, for details see in #3856.

Blaisorblade pushed a commit to dotty-staging/dotty that referenced this issue Mar 1, 2018
@smarter
Copy link
Member Author

smarter commented Mar 23, 2018

@odersky I see a fix for this issue authored by you in https://github.com/dotty-staging/dotty/commits/fix-%232973 but no corresponding PR, did you forget to open the PR?

@Blaisorblade
Copy link
Contributor

@smarter I already opened #4057 with that fix, but it doesn't work and I couldn't immediately fix it (my comments there explain why): IIRC, if you compute variance by traversing classParents of a ClassInfo, you don't see the annotations because they're just not there.

Blaisorblade pushed a commit to dotty-staging/dotty that referenced this issue Aug 11, 2018
@Blaisorblade Blaisorblade assigned Blaisorblade and unassigned odersky Aug 11, 2018
Blaisorblade pushed a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
Blaisorblade added a commit that referenced this issue Aug 26, 2018
Fix #2973: Check variances of class parents
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 26, 2018
Blaisorblade added a commit that referenced this issue Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants