Skip to content

Call on self type leads to IllegalAccessError #13007

Closed
scala/scala
#10794
@lrytz

Description

@lrytz

Java:

package j;
public class J {
  protected boolean i() { return false; }
}

Scala:

package s

trait T { self: j.J =>
  override def i(): Boolean = self.i() || true;
}
class C extends j.J with T

object Test {
  def main(args: Array[String]): Unit = {
    println(new C().i())
  }
}

This crashes with IllegalAccessError: class s.T tried to access protected method j.J.i.

Before scala/scala#8835, the compiler actually emitted a protected accessor in this example, so self.i was actually acting like a super call.

If the two classes are in the same package, the method J.i is accessible. In this case the runtime behavior is actually an infinite recursion, as it should be.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions