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

spec should explicitly state that qualified private members can be inherited #9321

Closed
scabug opened this issue May 20, 2015 · 4 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 20, 2015

For the following code:

object p {
  trait A {
    private[p] val m = 1
  }
}

trait B {
  val m = "1"
}
trait Mix extends p.A with B

I get the message:

  value m in trait A of type Int  and
  value m in trait B of type String
 (Note: this can be resolved by declaring an override in trait Mix.)
 trait Mix extends p.A with B

Maybe my expectations are incorrect but I expected the package protected member to never conflict with another member outside of the definition package.

@scabug
Copy link
Author

scabug commented May 20, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9321?orig=1
Reporter: @etorreborre
Affected Versions: 2.11.6

@scabug
Copy link
Author

scabug commented May 21, 2015

@retronym said:
Here's a tighter look at this. Relevant spec extracts inline:

object p {
  trait A {
    private val privateMember = 1
    private[p] val qualifiedPrivateMember = 1
  }

  // The private modifier can be used with any definition or declaration in a template.
  // Such members can be accessed only from within the directly enclosing template and
  // its companion module or companion class. They are not inherited by subclasses and
  // they may not override definitions in parent classes.
  def usePrivate(b: Mix) =
    b.privateMember // not a member

  // The modifier can be qualified with an identifier C (e.g. private[C]) that must
  // denote a class or package enclosing the definition. Members labeled with such a
  // modifier are accessible respectively only from code inside the package C or only
  // from code inside the class C and its companion module.

  def useQualifiedPrivate(b: Mix) =
    b.qualifiedPrivateMember // allowed, but should it be?
}

trait Mix extends p.A

@scabug
Copy link
Author

scabug commented May 21, 2015

@retronym said:
We're clarifying the spec to say this is as designed: scala/scala#4512

@scabug scabug closed this as completed May 26, 2015
@scabug
Copy link
Author

scabug commented May 27, 2015

@etorreborre said:
Thanks Jason for looking into this.

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