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

TypeChecked/CompileStatic index out of bounds

    XMLWordPrintableJSON

Details

    Description

      The latest patch release changed something in the type checker that broke the following code. The thing that breaks is the cast (B) this if that is replaced with this as B it works.

      import groovy.transform.CompileStatic
      
      @CompileStatic
      abstract class Example<B extends Example<B, R>,  R> {    
          B fluentMethod() {
             (B)  this
          }
      }
       

      Try it in the Groovy Web Console (as long as the version is still 3.0.10)

      Fails with

      General error during canonicalization: Index 1 out of bounds for length 1
      
      java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
              at org.codehaus.groovy.ast.GenericsType.compareGenericsWithBound(GenericsType.java:369)
              at org.codehaus.groovy.ast.GenericsType.checkGenerics(GenericsType.java:296)
              at org.codehaus.groovy.ast.GenericsType.isCompatibleWith(GenericsType.java:222)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isAssignableTo(StaticTypeCheckingSupport.java:468)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.checkCast(StaticTypeCheckingVisitor.java:4174)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitCastExpression(StaticTypeCheckingVisitor.java:4141)
              at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:90)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:200)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitExpressionStatement(StaticTypeCheckingVisitor.java:2154)
              at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:40)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:164)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBlockStatement(StaticTypeCheckingVisitor.java:3960)
              at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:138)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:111)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2143)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:106)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2576)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2539)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitConstructorOrMethod(StaticCompilationVisitor.java:236)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:251)
              at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1100)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1093)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:414)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:197)
              at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:67)
              at org.codehaus.groovy.transform.ASTTransformationVisitor.visitClass(ASTTransformationVisitor.java:143)
              at org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$addPhaseOperations$2(ASTTransformationVisitor.java:221)
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:671)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:635)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:610)
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              leonard84 Leonard Brünings
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: