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

NullPointerException in instruction selection phase when having parameterized method

    XMLWordPrintableJSON

Details

    Description

      The following (complicated) test case makes the compiler produce an NullPointerException:

      class Foo<T> {
        Foo(T x) {}
      
        <T extends Short> T m(T x) {
          x
        }
      }
      
      class Test {
        static final void test() {
          Foo<Integer> tmp = new Foo<Integer>(-76);
          boolean cond = 5.0 > tmp.m(new Foo<Integer>(95).m(null));
        }
      }
      

      This is the stacktrace:

      >>> a serious error occurred: BUG! exception in phase 'instruction selection' in source unit 'test.groovy' unexpected NullPointerException
      >>> stacktrace:
      BUG! exception in phase 'instruction selection' in source unit 'test.groovy' unexpected NullPointerException
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:942)
              at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:692)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:666)
              at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:647)
              at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:311)
              at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:240)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:165)
              at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:205)
              at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:189)
      Caused by: java.lang.NullPointerException
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getPrimitiveDistance(StaticTypeCheckingSupport.java:919)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.getDistance(StaticTypeCheckingSupport.java:935)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.allParametersAndArgumentsMatch(StaticTypeCheckingSupport.java:377)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.measureParametersAndArgumentsDistance(StaticTypeCheckingSupport.java:1118)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.chooseBestMethods(StaticTypeCheckingSupport.java:1072)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.chooseBestMethod(StaticTypeCheckingSupport.java:1049)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.findMethod(StaticTypeCheckingVisitor.java:4859)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.findMethodOrFail(StaticTypeCheckingVisitor.java:4596)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.findMethodOrFail(StaticCompilationVisitor.java:369)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.getResultType(StaticTypeCheckingVisitor.java:4440)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:843)
              at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:57)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitBinaryExpression(StaticTypeCheckingVisitor.java:828)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitDeclarationExpression(CodeVisitorSupport.java:356)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitDeclarationExpression(ClassCodeVisitorSupport.java:161)
              at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:92)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:117)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:212)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitExpressionStatement(StaticTypeCheckingVisitor.java:2193)
              at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41)
              at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:175)
              at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:70)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:139)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:118)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.lambda$visitConstructorOrMethod$27(StaticTypeCheckingVisitor.java:2622)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.doWithTypeCheckingExtensions(StaticTypeCheckingVisitor.java:457)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitConstructorOrMethod(StaticTypeCheckingVisitor.java:2622)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:110)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.startMethodInference(StaticTypeCheckingVisitor.java:2605)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethod(StaticTypeCheckingVisitor.java:2584)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitConstructorOrMethod(StaticCompilationVisitor.java:189)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitMethod(StaticCompilationVisitor.java:204)
              at org.codehaus.groovy.ast.ClassNode.visitMethods(ClassNode.java:1143)
              at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1136)
              at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.lambda$visitClass$3(StaticTypeCheckingVisitor.java:493)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.doWithTypeCheckingExtensions(StaticTypeCheckingVisitor.java:457)
              at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitClass(StaticTypeCheckingVisitor.java:493)
              at org.codehaus.groovy.transform.sc.StaticCompilationVisitor.visitClass(StaticCompilationVisitor.java:151)
              at org.codehaus.groovy.transform.sc.StaticCompileTransformation.visit(StaticCompileTransformation.java:68)
              at org.codehaus.groovy.control.customizers.ASTTransformationCustomizer.call(ASTTransformationCustomizer.groovy:303)
              at org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:937)
              ... 8 more
      
      

      Tested against master (commit: d7fa923bed20945074a41c54cce5133cc2ab63a0)

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: