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

Confusing Compiler Error For Static Method Calls

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.2
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      groovy $ cat Demo.groovy 
      @groovy.transform.CompileStatic
      class Demo {
          def someMethod() {
              String.doSomething()
          }
      }
      groovy $ 
      groovy $ groovyc Demo.groovy 
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Demo.groovy: 4: [Static type checking] - Cannot find matching method java.lang.Class#doSomething(). Please check if the declared type is right and if the method exists.
       @ line 4, column 3.
         		String.doSomething()
           ^
      
      1 error
      

      I think it would make more sense to refer to java.lang.String#doSomething() rather than java.lang.Class#doSomething(). I understand that there may be complications related to the type checker making a distinction between String.doSomething() and Class<String>.doSomething() but I am filing this here to prompt a look at the issue to see if the situation can be improved.

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              brownj Jeff Brown
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: