Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
There is a dispatch bug in CompileStatic with overloaded method when last argument is an array and there is an separate method without the last array argument.
Example of such method signatures:
List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes); List<MetaMethod> respondsTo(Object obj, String name);
This example demonstrates the bug:
class Hello { def hello() { "Hello" } def hello(String name) { "Hello $name" } } class DispatchBug { def e=new Hello() @groovy.transform.CompileStatic def demo() { def d=new Hello() println org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(d).respondsTo(d, "hello") println org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(e).respondsTo(e, "hello") } def demoDynamic() { def d=new Hello() println org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(d).respondsTo(d, "hello") println org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(e).respondsTo(e, "hello") } } def bugdemo=new DispatchBug() bugdemo.demo() bugdemo.demoDynamic()
It prints out:
[public java.lang.Object Hello.hello()] [public java.lang.Object Hello.hello(), public java.lang.Object Hello.hello(java.lang.String)] [public java.lang.Object Hello.hello(), public java.lang.Object Hello.hello(java.lang.String)] [public java.lang.Object Hello.hello(), public java.lang.Object Hello.hello(java.lang.String)]