bug icon indicating copy to clipboard operation
bug copied to clipboard

Self-type should not grant access to protected members

Open som-snytt opened this issue 2 years ago • 1 comments

Reproduction steps

Scala version: 2.13.11

package p {
  class C {
    protected def f() = ()
  }
  class X {
    this: C =>
    def g() = f()
  }
}
package p.s {
  import p._
  class Y {
    this: C =>
    def g() = f()
  }
}
package q {
  import p._
  class Z {
    this: C =>
    def g() = f() // illegal access to protected method f in class C from class Z
  }
}

Problem

Access to protected f requires that the enclosing class X be a subclass of C, not merely that this is.

Dotty currently allows access within p, per the linked ticket, but disallows in q.

Scala 2 accepts the example.

Noticed at https://github.com/lampepfl/dotty/issues/18245

som-snytt avatar Aug 08 '23 18:08 som-snytt

Unlikely to progress; but note that there is a new dotty ticket linked from the linked dotty ticket.

som-snytt avatar Dec 12 '25 23:12 som-snytt