Paul King created GROOVY-7442:
---------------------------------

             Summary: spread operator within assert isn't expected
                 Key: GROOVY-7442
                 URL: https://issues.apache.org/jira/browse/GROOVY-7442
             Project: Groovy
          Issue Type: Bug
            Reporter: Paul King


This source:
{code}
@groovy.transform.CompileStatic
def myMethod(String a, String b) {
  assert [a, b]*.size() == [5, 5]
}

myMethod('hello', 'world')
{code}
Results in this compile error:
{noformat}
BUG! exception in phase 'class generation' in source unit 'ConsoleScript1' In 
method public java.lang.Object MyMethod(java.lang.String a, java.lang.String b) 
 { ... }, CompileStack#removeVar: tried to remove a temporary variable with 
index 3 in wrong order. Current temporary 
variables=[iterator(index=6,type=java.util.Iterator <E extends java.lang.Object 
-> java.lang.Object>,holder=false), 
recorder(index=3,type=java.lang.Object,holder=false)]
    at 
org.codehaus.groovy.classgen.asm.CompileStack.removeVar(CompileStack.java:226)
    at 
org.codehaus.groovy.classgen.asm.AssertionWriter.writeAssertStatement(AssertionWriter.java:136)
    at 
org.codehaus.groovy.classgen.asm.StatementWriter.writeAssert(StatementWriter.java:550)
    at 
org.codehaus.groovy.classgen.AsmClassGenerator.visitAssertStatement(AsmClassGenerator.java:587)
*/
{noformat}
but this compiles and runs fine:
{code}
@groovy.transform.CompileStatic
def myMethod(String a, String b) {
  def result = [a, b]*.size()
  assert result == [5, 5]
}

myMethod('hello', 'world')
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to