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
@vararg annotation when called from Java does not compile #7212
Comments
Someone (SO) asked about overloaded
and invocation from Java
In Scala 3, modulo
instead of
Now, whenever something doesn't work as expected, we ask, WWDD? |
Are there any workaround for this issue now? Minimal test code: class Dotty {
@annotation.varargs def f(a: String*)= ???
} public class Java {
Dotty d = null;
public void test() {
d.f("a", "b");
}
} [error] .../Java.java:4:1: method f in class Dotty cannot be applied to given types;
[error] required: scala.collection.immutable.Seq<java.lang.String>
[error] found: java.lang.String,java.lang.String
[error] reason: actual and formal argument lists differ in length
[error] d.f |
I just did the thing where I forgot to Anyway, the ball is now in javac's court:
Edit: I see that was already reported on the linked scala ticket. |
Is there a link to the test or anything we can review? |
Workaround for scala/scala3#7212
It turns out that dotty generates no java varargs method, as if the Side note : |
Yeah, it doesn't do anything with it right now.
I don't think this needs to be handled in the backend (it isn't in scalac as far as I can see). It should probably be handled in https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala which already takes care of adding varargs bridge to scala methods that override java methods. |
alright! can I try to implement it there? What about |
Sure! For |
Works great! |
minimized code
expectation
Calling from Scala works as expected compared to Scala 2. In Dotty calling from Java does not compile and it looks like it calls the Scala method based on the error.
Reference used when porting https://github.com/ekrich/sconfig from Java to Scala. scala/bug#10658
The text was updated successfully, but these errors were encountered: