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

IllegalArgumentException when invoking applyDynamic on a Selectable #16984

Open
dgruntz opened this issue Feb 21, 2023 · 1 comment
Open

IllegalArgumentException when invoking applyDynamic on a Selectable #16984

dgruntz opened this issue Feb 21, 2023 · 1 comment

Comments

@dgruntz
Copy link

dgruntz commented Feb 21, 2023

Compiler version

3.2.0

Minimized code

import scala.reflect.Selectable.reflectiveSelectable
def f : { def foo(as: String*): String } = new {
   def foo(s: String*) = s.toList.mkString
}
f.foo()
f.foo("f", "oo")

Output

scala> f.foo("f", "oo")
java.lang.IllegalArgumentException: wrong number of arguments
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
  at scala.reflect.Selectable.applyDynamic(Selectable.scala:40)
  at scala.reflect.Selectable.applyDynamic$(Selectable.scala:11)
  at scala.reflect.Selectable$DefaultSelectable.applyDynamic(Selectable.scala:51)
  ... 34 elided

Expectation

No exception should be thrown and the result of the two invocations should be the empty string or the string "foo", i.e. the behaviour should be similar as if explicit types were used:

trait FOO { def foo(as: String*): String }
def f : FOO = new {
   def foo(s: String*) = s.toList.mkString
}
f.foo()
f.foo("f", "oo")
@dgruntz dgruntz added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 21, 2023
@Kordyjan Kordyjan added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 22, 2023
@Kordyjan Kordyjan added this to the Future versions milestone Feb 22, 2023
@prolativ
Copy link
Contributor

It looks like the problem is because varargs are erased to Seq so there's a mismatch between what the implementation of applyDynamic in reflect.Selectable gets from reflection and what the compiler would expect to be there. Seems related to #16995

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

3 participants