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

CompileStatic on templated classes with multiple template constraints

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.4
    • Fix Version/s: 2.4.0-rc-1
    • Component/s: Static Type Checker
    • Labels:
    • Environment:
      Windows 7, jdk 1.8.0_20 64-bit

      Description

      A @CompileStatic compilation of the below file

      package myBugReport
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      abstract class MyCompileStaticBugG<TertiaryT extends TertiaryG> {
        TertiaryT myProp
      
        // workaround: if @CompileDynamic this method, it compiles just fine.  But this is the bug - it should @CompileStatic...
        void load() {
            if (myProp == null)
            {
              myProp = loadProp()
            }
          }
      
          abstract TertiaryT loadProp()
      }
      
      @CompileStatic
      abstract class PrimaryG {}
      
      @CompileStatic
      abstract class SecondaryG<PrimaryT extends PrimaryG> {}
      
      @CompileStatic
      abstract class TertiaryG<PrimaryT extends PrimaryG, SecondaryT extends SecondaryG<PrimaryT>> {}
      

      results in the following exception:

      Error:Groovyc: java.lang.ArrayIndexOutOfBoundsException: 1
      	at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:143)
      	at org.codehaus.groovy.ast.tools.GenericsUtils.parameterizeType(GenericsUtils.java:219)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:549)
      	at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:49)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:193)
      	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitIfElse(StaticTypeCheckingVisitor.java:2948)
      	at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)
      	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:163)
      	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:1614)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1933)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1892)
      	at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:144)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1063)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:240)
      	at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:110)
      	at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:61)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:132)
      	at org.codehaus.groovy.transform.ASTTransformationVisitor$2.call(ASTTransformationVisitor.java:176)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1047)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:583)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:561)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:538)
      	at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:54)
      	at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:87)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:100)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
      

      Unfortunately, the exception gives no clue as to what is wrong in the code (the stacktrace does not reference where the error occurs), so it is a fairly painful bug. I narrowed it down to the 'load' method in the above simplified version of the code: if I add the @CompileDynamic annotation to the 'load' method, the exception goes away.

      Groovy should be able to @CompileStatic, as the equivalent Java code compiles just fine (equivalent java is also included in the zip file).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ilbmiller Brad Miller
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: