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

Incorrect parsing of comma-separated variable declaration as single statement after if/while/for

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.8
    • Component/s: None
    • Labels:
      None

      Description

      Currently during parsing a single (comma-separated) variable declaration is turned into multiple statements on the fly. If this occurs when such a statement is the single statement after an if/while/for, then only the first statement is picked up and the next is left dangling within the AST tree. For 'if' it becomes the else statement! while in the 'for/while' cases I think it is ignored. So, the following code doesn't work as expected:

      int xNext = 0, yNext = 0
      if (false) int x = xNext++, y = yNext++
      assert xNext == 0 && yNext == 0
      if (true) int x = xNext++, y = yNext++
      assert xNext == 1 && yNext == 1
      

      This is very much an edge case (what good is a declaration if you then have no block in which to use it?) but is still worth fixing.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                paulk Paul King
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: