Skip to content

Migrate Markdown Adjustments - #20

Open
cheeseng wants to merge 2 commits into
feature-todo-writerfrom
feature-triple-quote-block-adjustments
Open

Migrate Markdown Adjustments#20
cheeseng wants to merge 2 commits into
feature-todo-writerfrom
feature-triple-quote-block-adjustments

Conversation

@cheeseng

Copy link
Copy Markdown
Collaborator
  1. When translating {{{...}}}, it will be translated to:
...

for existing ..., it will be translated to the above format as well.

  1. Enhanced code to detect in code, to avoid adding \n before */ when it is in code.

```
...
```
for existing ```...```, it will be translated to the above format as well.
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