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

Problem With Static Imports

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.0-rc-1, 2.4.0-rc-2, 2.4.0
    • Fix Version/s: 2.4.1
    • Component/s: Compiler
    • Labels:
      None

      Description

      The attached staticimport.zip contains the following:

      src/main/groovy/demo/util/Helper.java
      package demo.util;
      
      public abstract class Helper {
          public static class Foo {}
      }
      
      src/main/groovy/demo/Demo.groovy
      package demo
      
      import demo.util.Helper
      import static demo.util.Helper.*
      
      class Demo extends Helper {
          Foo foo
      }
      

      The code will not compile with Groovy 2.4.0-rc-1, 2.4.0-rc-2 or 2.4.0.

      $ ./gradlew clean cG
      :clean
      :compileJava UP-TO-DATE
      :compileGroovy
      startup failed:
      /Users/jeff/staticimport/src/main/groovy/demo/Demo.groovy: 7: unable to resolve class Foo 
       @ line 7, column 5.
             Foo foo
             ^
      
      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: 4.257 secs
      staticimport master $
      

      If I edit build.gradle and change the Groovy version to 2.3.9 then the code will compile. Also, the problem doesn't appear to happen if Demo does not extend Helper.

        Attachments

        1. staticimport.zip
          50 kB
          Jeff Brown

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              brownj Jeff Brown
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: