Skip to content

qualified private and protected not rendered by tree printers #620

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
retronym opened this issue May 29, 2015 · 2 comments · Fixed by #6593 or #6642
Closed

qualified private and protected not rendered by tree printers #620

retronym opened this issue May 29, 2015 · 2 comments · Fixed by #6593 or #6642
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug prio:low

Comments

@retronym
Copy link
Member

class D {
  class C {
    protected[D] def a = 0
    private[D]   def b = 0
  }
}
% ./bin/dotc -Xprint:frontend sandbox/test.scala
result of sandbox/test.scala after frontend:
package <empty> {
  class D() extends Object() {
    class C() extends Object() {
      protected def a: Int = 0
      def b: Int = 0
    }
  }
}

I was trying to test whether access was properly propagated from constructor params to param accessors, but this but made that difficult. Once this is fixed, it would be good to systematically review derivation of accessors, case- implicit-class factories, etc. to make sure access is coherent.

This is another area where you shouldn't assume the scalac is doing the right thing, e.g. implicit classes get a factory method that circumvents the access of the constructor.

scalac -Xprint:typer sandbox/test.scala
[[syntax trees at end of                     typer]] // test.scala
package <empty> {
  object O extends scala.AnyRef {
    def <init>(): O.type = {
      O.super.<init>();
      ()
    };
    implicit class C extends scala.AnyRef {
      <paramaccessor> private[this] val a: Any = _;
      private[O] def <init>(a: Any): O.C = {
        C.super.<init>();
        ()
      }
    };
    implicit <synthetic> def C(a: Any): O.C = new C(a)
  }
}
@retronym
Copy link
Member Author

Followup from #617, /cc @smarter

@DarkDimius
Copy link
Contributor

AFAIK qualified private and protected aren't supposed to work at all, as we are considering removing them.

@smarter smarter added itype:bug prio:low area:reporting Error reporting including formatting, implicit suggestions, etc labels Jan 10, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue May 31, 2019
odersky added a commit that referenced this issue Jun 5, 2019
Fix #620: show privateWithin in tree printing
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 8, 2019
Reverts:
  Fix scala#620: show privateWithin in tree printing (reverted from commit 8a7e01e)

The previous fix messed up printing of all private definitions that did not have a privateWithin.
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2019
The issue in scala#6642 shows that errors may be latent in seemingly
simple fixes if not tested, which can backlash us at critical moment.
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2019
The issue in scala#6642 shows that errors may be latent in seemingly
simple fixes if not tested, which can backlash us at critical moment.
anatoliykmetyuk added a commit that referenced this issue Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug prio:low
Projects
None yet
3 participants