Skip to content

Fix #2066: Don't qualify private members in SelectionProto's... #2080

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

Merged
merged 2 commits into from
Mar 12, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 12, 2017

... unless they would be accessible in the given context.

... unless they would be accessible in the given context.
@odersky odersky requested a review from smarter March 12, 2017 12:39
@liufengyun
Copy link
Contributor

The fix fails the following case if we change private to protected:

class Foo

object Test {
  implicit class One(x: Foo) {
    def meth: Unit = {}
  }

  implicit class Two(x: Foo) {
    protected def meth: Unit = {}    //  <==== change private to protected
  }

  def test(foo: Foo): Unit = {
    foo.meth
  }
}

@odersky
Copy link
Contributor Author

odersky commented Mar 12, 2017

The fix fails the following case if we change private to protected:

That's expected. private behaves differently from the other modifiers. For private/non-private we have different ways to search. For the other modifiers we search first, and then check that the result is accessible. But that check plays no role in (say) overloading resolution or implicit search. This has been always like this and it would be really hard to change.

@smarter
Copy link
Member

smarter commented Mar 12, 2017

Is this as expected? This doesn't compile:

class Foo

object Test {
  implicit def two(x: Foo): Two = new Two(x)

  class Two(x: Foo) {
    private def meth: Unit = {}

    def test2(foo: Foo): Unit = {
      foo.meth
    }
  }
}

But this does:

class Foo

object Test {

  class Two(x: Foo) {
    implicit def two(x: Foo): Two = new Two(x)

    private def meth: Unit = {}

    def test2(foo: Foo): Unit = {
      foo.meth
    }
  }
}

(Both fail with scalac)

@odersky
Copy link
Contributor Author

odersky commented Mar 12, 2017

Is this as expected? This doesn't compile:

No, this is weird. It looks like we can't do a good job distinguishing here without losing a lot of implicit cachability. So I'll change it to scalac's behavior to only look for non-private members.

@smarter
Copy link
Member

smarter commented Mar 12, 2017

Okay, this will require a spec change I think since the spec only mentions accessibility: http://www.scala-lang.org/files/archive/spec/2.12/07-implicits.html#views

@odersky
Copy link
Contributor Author

odersky commented Mar 12, 2017

So, does that mean scalac is also in disagreement with the spec here?

@smarter
Copy link
Member

smarter commented Mar 12, 2017

I think so yes, but I haven't looked closely.

Now we never match `? { name: T }` with types that
have only a private `name` member. This is what scalac does, too.
@odersky odersky merged commit b319440 into scala:master Mar 12, 2017
@allanrenucci allanrenucci deleted the fix#-2066 branch December 14, 2017 16:59
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

Successfully merging this pull request may close these issues.

3 participants