Scaladoc Overload Method Link Fix - #18
Open
cheeseng wants to merge 1 commit into
Open
Conversation
This was referenced Jan 23, 2026
…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
force-pushed
the
fix-scaladoc-reference-overload-methods-final
branch
from
January 28, 2026 02:17
4763a94 to
9b298f8
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.