-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Ambiguous method warning when there does not appear to be any ambiguity #2865
Comments
Actually, you can implement any interface with a block, so this is a valid message. It's just not particularly useful when the interface has many different and incompatible methods. However, I have thought that perhaps cases like this should only coerce if there's exactly one abstract method on the likely interface. It's not something we've done formally, though. As a workaround in the short term you can select the method you want using java_send, java_method, or java_alias. Note that when specifying interface types, you currently need to add .java_class: class my::pkg::MyClass
java_alias :open_file_callable, :openFile, [java.lang.String, Java::your::package::Consumer.java_class])
end The syntax for java_method and java_send is similar. @enebo How dangerous to compatiblity might it be if we modified Java method lookup to only coerce procs when the target interface has one abstract method? It would narrow down some ambiguous cases like this. |
Pardon my inconsistent use of |
Since I control the interface in this instance I could probably bump the method name on the Java side to get around it I guess... I was just trying to keep the interface as clean as possible. I also wondered whether there were an annotation to explicitly mark the methods intended to be used with blocks... I see what you're saying though I think... the intent is to support implementing multiple overloads all going to the same block, I gather... somehow I assumed it wasn't possible to implement multiple methods with a single block. It would be enough for me if the existence of a single abstract-method were used as a tiebreaker in this situation even if multi-method interfaces still worked in other more general situations. But I haven't taken a close look at how this part of type coercion works, so I'll let the experts decide. :) |
The minimal fix for 1.7 is something like this. The method I modified for 1.7 doesn't seem to exist anymore on master, though, which complicates things. Edit: Okay, I see, my change depends on commit c1a174f which was part of issue #2595, which is committed to 1.7 but not master. This makes sense, since both are sort of similar, looking at the argument type and using that to disambiguate the parameter lists. |
Well, tested my change on 9.0.0.0.rc1 and it doesn't work. But not only that, I looked at the code on 1.7.20 and couldn't figure out how it was working there either. So clearly it was the wrong way to do it. But now my attention is on this bit of
Here it seems to have computed that the candidate preference So is the correct way to do this to define a new |
…ace. Experimental change intended to fix issue jruby#2865.
Attempt 2, hakanai@8ef983d |
this is actually more of a "true" bug than it seems, I hoped its already fixed but its not, my notes:
what I'm seeing here is still non-determinism for the proc matching case (result depends on SDK's side note: we already have a functional-interface checking mechanism: jruby/core/src/main/java/org/jruby/javasupport/Java.java Lines 1485 to 1506 in f1353e3
|
will now account for all parameter types in a method signature and takes last arg proc matching into account - outcomes should be more predictable as noted (jruby#2865 (comment)) the selection has been still subject to non-deterministic behavior (depending on reflected method orded) esp. for cases where last argument is a proc to be matched as an interface impl fixes jruby#2865
I'm rediscovering this issue now on 9.0.5.0 but I'm not sure whether it's because this time I am passing an RSpec double, whereas maybe if I passed a block it would be 100% reliable. |
@trejkaz it's definitely possible that the RSpec double looks ambiguous to the JI subsystem. Running on a newer version of Java can sometimes cause this to come up due to overloads and new methods added to the core Java types. If you can narrow it down to a specific reportable oddity, please open a new issue and we'll help you look into it. |
I have two methods with the following signatures:
When I try to call the second one:
I get a warning:
I don't think there is any real ambiguity here. I can't implement
Map
using a block, so it should always callopenFile(String, Consumer)
.Reproduced on 1.7.18, 1.7.19, 9.0.0.0.pre1.
The text was updated successfully, but these errors were encountered: