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

unstable ambiguous overload resolution #4759

Closed
MartinNowak opened this issue Aug 28, 2017 · 1 comment
Closed

unstable ambiguous overload resolution #4759

MartinNowak opened this issue Aug 28, 2017 · 1 comment

Comments

@MartinNowak
Copy link

Environment

  • jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a OpenJDK 64-Bit Server VM 25.141-b16 on 1.8.0_141-b16 +jit [linux-x86_64]
  • Linux localhost.localdomain 4.12.5-300.fc26.x86_64 break script engine #1 SMP Mon Aug 7 15:27:25 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Expected Behavior

  • A warning should be emitted, but the overload selection should be stable, e.g. first of all equally good matches.

Actual Behavior

  • Different overloads are chosen each time.

Test case

java_import 'java.util.concurrent.Executors'

service = Executors.newFixedThreadPool(1)
future = service.submit(->() { return 42; })
puts "result: '#{future.get}'"
service.shutdown
jruby test.rb
test.rb:4: warning: ambiguous Java methods found, using submit(java.lang.Runnable)
jruby test.rb
test.rb:4: warning: ambiguous Java methods found, using submit(java.util.concurrent.Callable)

Just a guess, this seems like it depends on some unordered data structure, so using a sorted one or sorting overloads before resolution would fix the issue.

Workaround

Use java_send to manually pick the overload.

java_import 'java.util.concurrent.Callable'
future = service.java_send :submit, [Callable], ->() { return 42; }
@kares
Copy link
Member

kares commented Aug 28, 2017

this does not seem fixable - ordering won't help much as its still not clear which one you'd like JRuby to call.
both Callable and Runnable are functional interfaces that are equal matches for proc-to-iface resolution.

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

2 participants