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

@CompileStatic and @Delegate with generics causes compilation failure

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.9, 2.2.1
    • Fix Version/s: 2.2.2
    • Component/s: Static compilation
    • Labels:
      None

      Description

      @groovy.transform.CompileStatic
      class IntList {
      	@Delegate List<Integer> delegate
      }
      

      compiling this code yields the following compilation error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      General error during class generation: Internal compiler error while compiling /Users/abrown/tmp/groovy/test.groovy
      Method: MethodNode@1827580455[boolean add(java.lang.Object)]
      Line -1, expecting casting to boolean but operand stack is empty
      
      java.lang.ArrayIndexOutOfBoundsException: Internal compiler error while compiling /Users/abrown/tmp/groovy/test.groovy
      Method: MethodNode@1827580455[boolean add(java.lang.Object)]
      Line -1, expecting casting to boolean but operand stack is empty
      	at org.codehaus.groovy.classgen.asm.OperandStack.doConvertAndCast(OperandStack.java:327)
      	at org.codehaus.groovy.classgen.asm.OperandStack.doGroovyCast(OperandStack.java:294)
      	at org.codehaus.groovy.classgen.asm.StatementWriter.writeReturn(StatementWriter.java:584)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitReturnStatement(AsmClassGenerator.java:543)
      	at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:47)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:357)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:314)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:434)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1055)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:177)
      	at org.codehaus.groovy.control.CompilationUnit$15.call(CompilationUnit.java:794)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:572)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:185)
      	at groovy.lang.GroovyShell$2.run(GroovyShell.java:206)
      	at groovy.lang.GroovyShell$2.run(GroovyShell.java:204)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:204)
      	at groovy.lang.GroovyShell.run(GroovyShell.java:150)
      	at groovy.ui.GroovyMain.processOnce(GroovyMain.java:588)
      	at groovy.ui.GroovyMain.run(GroovyMain.java:375)
      	at groovy.ui.GroovyMain.process(GroovyMain.java:361)
      	at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
      	at groovy.ui.GroovyMain.main(GroovyMain.java:100)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
      	at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
      
      1 error
      

      Without the @CompileStatic annotation, the code compiles and works correctly. Additionally, using the raw type (ie: List, in this case), also compiles successfully and works. I also tried this with other generic types (Map, Collection, etc) and it produces similar compilation errors, but for different methods.

      Lastly, the following code works, where the generic type parameter comes from the class declaring the @Delegate field

      @groovy.transform.CompileStatic
      class TList<T> {
      	@Delegate Collection<T> delegate
      }
      

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              acourtneybrown Adam Brown

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment