scala / bug

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

Call on self type leads to IllegalAccessError #13007

Closed lrytz closed 5 months ago

lrytz commented 5 months ago

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 https://github.com/scala/scala/pull/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.

lrytz commented 5 months ago

What I found out: