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

spread-dot operator within assert isn't expected with @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.4.6
    • Static compilation
    • None

    Description

      This source:

      @groovy.transform.CompileStatic
      def myMethod(String a, String b) {
        assert [a, b]*.size() == [5, 5]
      }
      
      myMethod('hello', 'world')
      

      Results in this compile error:

      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)
      */
      

      but this compiles and runs fine:

      @groovy.transform.CompileStatic
      def myMethod(String a, String b) {
        def result = [a, b]*.size()
        assert result == [5, 5]
      }
      
      myMethod('hello', 'world')
      

      Attachments

        Activity

          People

            shils Shil Sinha
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: