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

@CompileStatic def map = new HashMap<>() crashes compiler

    XMLWordPrintableJSON

    Details

      Description

      Code like:

      @CompileStatic
      void test()

      { def map = new HashMap<>() }

      breaks compiler with stacktrace:

      Groovyc: java.lang.NullPointerException
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferDiamondType(StaticTypeCheckingVisitor.java:565)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:482)
      at org.codehaus.groovy.ast.CodeVisitorSupport.visitDeclarationExpression(CodeVisitorSupport.java:245)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitDeclarationExpression(ClassCodeVisitorSupport.java:107)
      at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:86)
      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.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:1330)
      at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:1602)
      at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:1575)
      at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:120)
      at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:72)
      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: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 org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:54)
      at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:80)
      at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:85)
      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:601)
      at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)

        Attachments

        1. CompileStaticDiamondTest.groovy
          0.6 kB
          MIchail Nikolaev

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              Nkey MIchail Nikolaev
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: