scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Self-type should not grant access to protected members #12839

Open som-snytt opened 10 months ago

som-snytt commented 10 months ago

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