Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call Scala 3 inline methods from within Java #19346

Closed
mdedetrich opened this issue Dec 30, 2023 · 2 comments
Closed

Unable to call Scala 3 inline methods from within Java #19346

mdedetrich opened this issue Dec 30, 2023 · 2 comments

Comments

@mdedetrich
Copy link

mdedetrich commented Dec 30, 2023

Compiler version

3.3.1

Minimized code

See https://github.com/mdedetrich/call-scala3-inline-from-java-source for a reproducible example

object Inline {
  inline def myMethod: String = ""
}
public class CallInline {
    public void callInline() {
        Inline$.MODULE$.myMethod();
        return;
    }
}

Output

[error] /Users/mdedetrich/github/call-scala3-inline-from-java-source/src/main/java/CallInline.java:4:1: cannot find symbol
[error]   symbol:   method myMethod()
[error]   location: variable MODULE$ of type Inline$
[error] Inline$.MODULE$.myMethod
[error] (Compile / compileIncremental) javac returned non-zero exit code
[error] Total time: 0 s, completed 30 Dec 2023, 15:29:54

Expectation

For the Java source to compile. It appears that unlike Scala 2 with the @inline annotation, Scala 3 will strip the necessary symbols in the produced bytecode when using inline keyword which means its not callable from within Java sources.

For obvious reasons its not expected that Java is actually able to inline the method but rather that it can call it as a standard method without any inlining.

@sjrd
Copy link
Member

sjrd commented Dec 30, 2023

This is by design. inline requires inlining. Since Java cannot inline the method, it's not allowed to call it at all.

@He-Pin
Copy link

He-Pin commented Dec 31, 2023

@sjrd can we do inlining on the scala calls idempotent but still generate method for java usage ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants