[ 
https://issues.apache.org/jira/browse/GROOVY-8660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17364269#comment-17364269
 ] 

Daniil Ovchinnikov commented on GROOVY-8660:
--------------------------------------------

This should be documented somewhere. Last time I've checked, there was 
something like: "if a method can be called with a single null argument, then 
the argument can be omitted", there was no mention that the method must not 
have overloads or varargs. 

If {{new OnlyVararg().foo()}} fails
=> {{Both#foo(Object, [LObject;)}} must be inapplicable
=>  method selection in {{new Both().foo()}} should try only 
{{Both#foo(Object)}} against {{null}} argument 
=> {{Both#foo(Object)}} should be selected.

Now let's reverse the above.

If {{Both#foo(Object)}} is not selected
=> method selection in {{new Both().foo()}} actually sees both methods as 
applicable before trying them with null argument
=> {{Both#foo(Object, [LObject;)}} was applicable
=> {{new OnlyVararg().foo()}} must not fail.

I'm having trouble understanding `org.codehaus.groovy.*` code. Can you describe 
me the algorithm in human words, please?

> Unexpected MethodSelectionException with implicit null argument
> ---------------------------------------------------------------
>
>                 Key: GROOVY-8660
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8660
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.0-alpha-2, 2.4.15, 2.5.0
>            Reporter: Daniil Ovchinnikov
>            Priority: Major
>
> {code:groovy}
> class OnlySingle {
>     def foo(a) { "single param: $a" }
> }
> println new OnlySingle().foo()
> // as expected: 'single param: null'
> class OnlyVararg {
>     def foo(a, ... b) { "vararg param: $a, $b" }
> }
> println new OnlyVararg().foo()
> // as expected: 'MME: No signature of method: OnlyVararg.foo() is applicable 
> for argument types: () values: []'
> class Both {
>     def foo(a) { "single param: $a" }
>     def foo(a, ... b) { "vararg param: $a, $b" }
> }
> println new Both().foo()
> // unexpected:
> // MethodSelectionException: Could not find which method foo() to invoke from 
> this list:
> //  public java.lang.Object Both#foo(java.lang.Object)
> //  public transient java.lang.Object Both#foo(java.lang.Object, 
> [Ljava.lang.Object;)
> {code}
> If the exception is expected then {{OnlyVararg}} case should work too.
> If the exception is unexpected then {{Both#foo(Object)}} should be selected.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to