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

Overriding qualified private or protected members doesn't work #1994

Closed
scabug opened this issue May 18, 2009 · 3 comments
Closed

Overriding qualified private or protected members doesn't work #1994

scabug opened this issue May 18, 2009 · 3 comments

Comments

@scabug
Copy link

scabug commented May 18, 2009

class A {
  protected def x = 0
  protected[A] def y = 0
}

class B extends A {
  override def x = 1
  println(super[A].y)
  override def y = 1
}

gives the following compile error:

P.scala:9: error: method y overrides nothing
  override def y = 1
               ^
one error found

This is either a misleading error message, since A.y is definitely visible in B or as I think a plain error. Section 5.1.4 of the spec doesn't disallow this.

The same applies for qualified private members as in:

class A {
  class B {
    private[A] def x = 0
  }

  class C extends B {
    override def x = 1
  }
}
@scabug
Copy link
Author

scabug commented May 18, 2009

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

@scabug
Copy link
Author

scabug commented May 18, 2009

@paulp said:
This is mostly a duplicate of #1352. The issue is not that you can't override them, but that you can't widen the visibility to public. This works:

class A {
  class B {
    private[A] def x = 0
  }

  class C extends B {
    override private[A] def x = 1
    // or even this works
    // override protected[A] def x = 1
  }
}

My "mostly" qualifier above is because it doesn't look like you can override def y in your first example, because A is not an enclosing class inside B:

//   override protected[A] def y = 1
a.scala:9: error: A is not an enclosing class
  override protected[A] def y = 1
                            ^
//   override protected def y = 1
a.scala:9: error: method y overrides nothing
  override protected def y = 1
                         ^
//   override protected[B] def y = 1
a.scala:9: error: method B$$$$y overrides nothing
  override protected[B] def y = 1
                            ^

@scabug
Copy link
Author

scabug commented May 26, 2009

@dragos said:
This has to do with the mangling scheme for class protected members, which needs to be changed. Contributions are welcome.

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

2 participants