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

CompileStatic confuses statically importing an instance and statically importing a method

    XMLWordPrintableJSON

Details

    Description

      When statically importing a field and immediately calling a call() method on it, the static compiler gets confused and looks for a static method with the name of the field that takes the arguments passed to the call() method.

      See below - comment out @CompileStatic and it will run as expected.

      import groovy.transform.CompileStatic
      
      class WithCall {
      
          static final WithCall staticallyImported = new WithCall()
      
          String call(String input) {
              return input;
          }
      }
      
      class CompileStaticImport {
      
          @CompileStatic
          public static void main(String[] args) {
              assert WithCall.staticallyImported("to print") == "to print"
          }
      }
      

      Error:(16, 16) Groovyc: [Static type checking] - Cannot find matching method WithCall#staticallyImported(java.lang.String). Please check if the declared type is right and if the method exists.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              mahoney Robert Elliot
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: