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

Diamond Inference broken with Static Compilation

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.1
    • Component/s: Static Type Checker
    • Labels:
      None
    • Environment:
      Groovy Version: 2.1.0-SNAPSHOT JVM: 1.6.0_32 Vendor: Sun Microsystems Inc. OS: Linux

      Description

      Example program:

      package example
      
      import groovy.transform.TypeChecked
      
      @TypeChecked
      class Rules {
      
          private final Map<String, String> bindings = new HashMap<>();
      
      }
      

      Causes Stacktrace:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      General error during instruction selection: 0
      
      java.lang.ArrayIndexOutOfBoundsException: 0
              at org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders(GenericsUtils.java:130)
              at org.codehaus.groovy.ast.tools.GenericsUtils.parameterizeInterfaceGenerics(GenericsUtils.java:166)
              at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.compareGenericsWithBound(GenericsType.java:301)
              at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.checkGenerics(GenericsType.java:261)
              at org.codehaus.groovy.ast.GenericsType$GenericsTypeMatcher.matches(GenericsType.java:228)
              at org.codehaus.groovy.ast.GenericsType.isCompatibleWith(GenericsType.java:153)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.typeCheckAssignment(StaticTypeCheckingVisitor.java:647)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitField(StaticTypeCheckingVisitor.java:951)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1048)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:216)
              at org.codehaus.groovy.transform.StaticTypesTransformation.visit(StaticTypesTransformation.java:70)
              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:1024)
              at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:562)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:540)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:517)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:496)
              at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:57)
              at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:213)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:146)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:176)
              at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:160)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
              at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
      
      1 error
      

      This was using the 2.1.0-SNAPSHOT built from 333084c467c18f2afc9460e58d48c43909ad8d1a of git MASTER. The problem disappears if you provide type arguments to the HashMap constructor or if you remove @TypeChecked.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                melix Cédric Champeau
                Reporter:
                richardwarburton Richard Warburton
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: