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

CompileStatic with a spread operator in a boolean expression causes compiler error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.6
    • 2.3.8
    • None

    Description

      When class is annotated with the CompileStatic and a spread operator is a leaf of a boolean expression, then compilation fails with a message:

      Error:Groovyc: BUG! exception in phase 'class generation' in source unit 'C:\A.groovy' operand stack contains 2 elements, but we expected only 0

      Code sample:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class A {
          A() {
              List<String> myList = [ ]
              if (myList*.isEmpty().any() && true) {
                  println 'hello'
              }
          }
      }
      
      Error:Groovyc: BUG! exception in phase 'class generation' in source unit 'C:\A.groovy' operand stack contains 2 elements, but we expected only 0
      	at org.codehaus.groovy.classgen.asm.OperandStack.castToBool(OperandStack.java:110)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitBooleanExpression(AsmClassGenerator.java:743)
      	at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:40)
      	at org.codehaus.groovy.classgen.asm.StatementWriter.writeIfElse(StatementWriter.java:279)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:572)
      	at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:41)
      	at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:81)
      	at org.codehaus.groovy.classgen.asm.sc.StaticTypesStatementWriter.writeBlockStatement(StaticTypesStatementWriter.java:49)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:556)
      	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.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:420)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:377)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:119)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructor(AsmClassGenerator.java:492)
      	at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1059)
      	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
      	at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:231)
      	at org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:805)
      	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:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	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:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            mparfianowicz Marek Parfianowicz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: