Skip to content

Scaladoc Overload Method Link Fix - #18

Open
cheeseng wants to merge 1 commit into
mainfrom
fix-scaladoc-reference-overload-methods-final
Open

Scaladoc Overload Method Link Fix#18
cheeseng wants to merge 1 commit into
mainfrom
fix-scaladoc-reference-overload-methods-final

Conversation

@cheeseng

Copy link
Copy Markdown
Collaborator

Fixed incorrect reference to overload methods, example can be seen at https://www.scala-lang.org/api/3.7.4/scala/collection/convert/AsJavaExtensions$BufferHasAsJava.html , where the asJava method it is linked to asJava method that takes Map, which is wrong, it should link to asJava that takes Buffer.

…ttps://www.scala-lang.org/api/3.7.4/scala/collection/convert/AsJavaExtensions$BufferHasAsJava.html , where the asJava method it is linked to asJava method that takes Map, which is wrong, it should link to asJava that takes Buffer.
@cheeseng
cheeseng force-pushed the fix-scaladoc-reference-overload-methods-final branch from 4763a94 to 9b298f8 Compare January 28, 2026 02:17
cheeseng pushed a commit that referenced this pull request Mar 7, 2026
Fix scala#22628

Super call like `super.m()` were emitted with `invokespecial`
where owner = `fun.symbol.owner` (the method declaration owner).

However, that is wrong for some inherited Java members:
the declaration owner can be less accessible than the direct superclass at the Scala call site. In that case it causes `IllegalAccessError` at runtime.

This aligns with the normal call behavior, see: scala@fa42b81

**example**

In the example below, `fun.symbol.owner` for `super.close()` is `InnerServerCallBase` (where `close` is declared) that is not accessible from `mycode` package.

```scala
// mylib/InnerServerCallBase.java (package-private)
package mylib;
abstract class InnerServerCallBase implements ServerCall {
  @OverRide public void close() {
    System.out.println("InnerServerCallBase.close");
  }
}

// mylib/PublicServerCallBase.java
package mylib;
public abstract class PublicServerCallBase extends InnerServerCallBase {}

// mycode/MyServerCall.scala
package mycode
class MyServerCall extends mylib.PublicServerCallBase:
  override def close(): Unit =
    println("MyServerCall.close")
    super.close()
```

As a result, Scala3 emits the following Java bytecode where `invokespecial` on non-accessible class method. And it causes `IllegalAccessError` at runtime.

Scala 3 (before):
```java
  0: getstatic     #18  // Field scala/Predef$.MODULE$:Lscala/Predef$;
  3: ldc           #20  // String MyServerCall.close
  5: invokevirtual #24  // Method scala/Predef$.println:(Ljava/lang/Object;)V
  8: aload_0
  9: invokespecial #28  // Method mylib/InnerServerCallBase.close:()V
 12: return
```

We should generate `invokespecial` on the call-site qualifier type instead, like Scala 2.13 emits.

Scala 2.13
```
  0: getstatic     #16  // Field scala/Predef$.MODULE$:Lscala/Predef$;
  3: ldc           #18  // String MyServerCall.close
  5: invokevirtual #22  // Method scala/Predef$.println:(Ljava/lang/Object;)V
  8: aload_0
  9: invokespecial #24  // Method mylib/PublicServerCallBase.close:()V
 12: return
```

This commit fixes the issue by using call-site qualifier type for invokespecial on super call.
cheeseng pushed a commit that referenced this pull request Mar 7, 2026
Fix scala#22628 
scala#24084 as well ?

Super call like `super.m()` were emitted with `invokespecial` where
owner = `fun.symbol.owner` (the method declaration owner).

However, that is wrong for some inherited Java members: the declaration
owner can be less accessible than the direct superclass at the Scala
call site. In that case it causes `IllegalAccessError` at runtime.

This aligns with the normal call behavior, see:
scala@fa42b81

**example**

In the example below, `fun.symbol.owner` for `super.close()` is
`InnerServerCallBase` (where `close` is declared) that is not accessible
from `mycode` package.

```scala
// mylib/InnerServerCallBase.java (package-private)
package mylib;
abstract class InnerServerCallBase implements ServerCall {
  @OverRide public void close() {
    System.out.println("InnerServerCallBase.close");
  }
}

// mylib/PublicServerCallBase.java
package mylib;
public abstract class PublicServerCallBase extends InnerServerCallBase {}

// mycode/MyServerCall.scala
package mycode
class MyServerCall extends mylib.PublicServerCallBase:
  override def close(): Unit =
    println("MyServerCall.close")
    super.close()
```

As a result, Scala3 emits the following Java bytecode where
`invokespecial` on non-accessible class method. And it causes
`IllegalAccessError` at runtime.

Scala 3 (before):
```java
  0: getstatic     #18  // Field scala/Predef$.MODULE$:Lscala/Predef$;
  3: ldc           #20  // String MyServerCall.close
  5: invokevirtual #24  // Method scala/Predef$.println:(Ljava/lang/Object;)V
  8: aload_0
  9: invokespecial #28  // Method mylib/InnerServerCallBase.close:()V
 12: return
```

We should generate `invokespecial` on the call-site qualifier type
instead, like Scala 2.13 emits.

Scala 2.13
```
  0: getstatic     #16  // Field scala/Predef$.MODULE$:Lscala/Predef$;
  3: ldc           #18  // String MyServerCall.close
  5: invokevirtual #22  // Method scala/Predef$.println:(Ljava/lang/Object;)V
  8: aload_0
  9: invokespecial #24  // Method mylib/PublicServerCallBase.close:()V
 12: return
```

This commit fixes the issue by using call-site qualifier type for
invokespecial on super call.

---

Huge thanks to @migesok for creating a reproducible example 🙌
https://github.com/migesok/scala3-bug-super-IllegalAccessError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant