Skip to content

qualified private and protected not rendered by tree printers #620

@retronym

Description

@retronym
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)
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcitype:bugprio:low

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions