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

Problem With Static Trait Methods

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.1
    • 2.4.2
    • None
    • None

    Description

      The attached statictraitmethods.zip contains the following:

      src/main/groovy/demo/SomeTrait.groovy
      package demo
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      trait SomeTrait {
      
          static someMethod() {
              List theNames = getNames()
              theNames
          }
      
          static List getNames() {
              ['Jeff', 'Betsy', 'Jake', 'Zack']
          }
      }
      

      The code will not compile:

      $ ./gradlew clean test
      :clean UP-TO-DATE
      :compileJava UP-TO-DATE
      :compileGroovy
      startup failed:
      /Users/jeff/statictraitmethods/src/main/groovy/demo/SomeTrait.groovy: 9: [Static type checking] - Cannot find matching method demo.SomeTrait#getNames(). Please check if the declared type is right and if the method exists.
       @ line 9, column 25.
                 List theNames = getNames()
                                 ^
      
      1 error
      
      :compileGroovy FAILED
      
      FAILURE: Build failed with an exception.
      
      * What went wrong:
      Execution failed for task ':compileGroovy'.
      > Compilation failed; see the compiler error output for details.
      
      * Try:
      Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
      
      BUILD FAILED
      
      Total time: 5.148 secs
      

      This may be the same problem as that described in GROOVY-7191. That issue describes the problem as relating to calling static methods from an instance method. The example above suggests that the problem is more general than that.

      Attachments

        1. statictraitmethods.zip
          50 kB
          Jeff Brown

        Issue Links

          Activity

            People

              melix Cédric Champeau
              brownj Jeff Brown
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: