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

CompileStatic cause inconsistent compilation error when varargs super method called (reference to method is ambiguous)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.0
    • 2.0.2
    • Compiler
    • None
    • Linux 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

    Description

      Consider an example base class:

      class BaseObject {
          void trace(Integer logLevel, Object... args) { /* ... */ }
          void trace(Object... args) { /* ... */ }
      }
      

      and the extending class:

      @CompileStatic
      class ChildObject extends BaseObject {
          void doSomething() {
              trace('test2')          // OK
              super.trace('test2')    // OK
              trace(1, 'test1')       // OK
              super.trace(1, 'test1') // compilation error
          }
      }
      

      When a type checked compilation is enabled following error appears on the last line of 2nd example class:

      [Static type checking] - Reference to method is ambiguous. Cannot choose between [MethodNode@1022828757[void trace([Ljava.lang.Object;)], MethodNode@76324664[void trace(java.lang.Integer, [Ljava.lang.Object;)]]

      I've come across this problem when extending closed library class which has methods of such signatures. Only difference is no Integer passed, but some custom class object of the library API as the 1st param. Compilation error is the same.
      Pay attention to the fact, that the error is thrown only when 'super' keyword preceding method call.

      Attachments

        Activity

          People

            melix Cédric Champeau
            topr Tomasz Przybysz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: