Skip to content

Unsoundness due to missing variance checks of private members #7567

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
joroKr21 opened this issue Nov 17, 2019 · 0 comments
Closed

Unsoundness due to missing variance checks of private members #7567

joroKr21 opened this issue Nov 17, 2019 · 0 comments

Comments

@joroKr21
Copy link
Member

minimized code

class A
class B extends A
class C extends A

object Foo {
  private[this] class Bar[+T](var x: T)
  def foo: B = {
    val barB: Bar[B] = new Bar(new B)
    val barA: Bar[A] = barB
    barA.x = new C
    barB.x
  }
}

Foo.foo

result

java.lang.ClassCastException

expectation

Variance error is reported.

variations

  • private is also broken in Dotty
  • private[this] is also broken in Scalac
  • private is detected in Scalac
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

1 participant