Jochen Theodorou commented on GROOVY-7933:

ah... I get a feeling I know the problem this is coming from. when doing 
a(foo), we may be able to do a direct method call in some cases. If foo is a 
boolean, then there must be a a(boolean) exist to work. If we do x.a(foo), then 
this is in dynamic Groovy never a direct call. To relialize the method call foo 
will be wrapped in an Object[] at some point and the type taken for the 
dispatch is the one out of this array. Which means foo will be Boolean instead. 
For Groovy with indy, this is different. Here foo will be the primitive type. 
And there is also the problem of MOP methods. For example an a(foo) in a 
Closure. This will cause method dispatch to go through an invokeMethod 
somewhere, or the MetaClass system, which too takes only an Object[] and not 
possibly known types from the callsite. So here again a(foo) would prefer 
a(Boolean). Using a cast helps carrying the information over, but only to the 
first MetaClass. After that, the information might get lost.

Not sure what way we should go to fix this. For indy there is actually nothing 
to fix here, if we ignore the MOP. And I am not sure it is really worth fixing 
it for non-indy Groovy. 

> Incorrect boxing of boolean primitive types
> -------------------------------------------
>                 Key: GROOVY-7933
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7933
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>            Reporter: Henri Tremblay
> A boolean primitive type seems to be boxed for no apparent reason. See the 
> example below. The problem disappear when using @CompileStatic or if 
> explicitly casting to (boolean).
> {code:java}
> public class Demo {
>    public void a(boolean a){
>        System.out.println("boolean was called");
>    }
>    public void a(Object a){
>        System.out.println("Object was called");
>    }
> }
> class Groovy {
>    static void main(String[] args) {
>        def demo = new Demo()
>        demo.a(true)
>    }
> }
> {code}
> *Output:*
> Object was called

This message was sent by Atlassian JIRA

Reply via email to