Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6147

CompileStatic: dispatch bug with overloaded method when last argument is an array and there is an separate method without the last array argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.1.4
    • Static compilation
    • 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)]
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            lhotari Lari Hotari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: