Skip to content

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

@som-snytt

Description

@som-snytt

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 scala/scala3#18245

Metadata

Metadata

Assignees

No one assigned

    Labels

    accessfixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions