Skip to content

Incorrect access check for heritability #12840

Open
@som-snytt

Description

@som-snytt

Reproduction steps

Scala version: 2.13.11

class C {
  private[C] def f = 42
}
class D extends C {
  override def f = 17 // incorrectly disallowed by Scala 2
  //override def f = super.f // correctly disallowed by Scala 3
}
object Test extends App {
  println {
    new D().f
  }
}

The example from the linked ticket should align with Scala 3:

package s1 {
  object O {
    class A {
      private[s1] def f1(): Int = 1
      private[O]  def f2(): Int = 2
      private[A]  def f3(): Int = 3
    }
  }
}
package s2 {
  class B extends s1.O.A {
    override def f1() = 11  // allowed
    override def f2() = 12  // allowed
    override def f3() = 13  // disallowed
    // ./a.scala:15: error: method f3 overrides nothing
    //     override def f3() = 12
    //                  ^
    // one error found
  }
}

Problem

Qualified private members are inherited, even if they are not accessible.

Follow-up to #2568
Follow-up to scala/scala3#10440

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