[ 
https://issues.apache.org/jira/browse/GROOVY-11601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17941476#comment-17941476
 ] 

Paul King commented on GROOVY-11601:
------------------------------------

So, for clarity, A would be allowed but B, C, D no longer.
{code:groovy}
// A
def items = []
for (int i = 3, j = 70; i < 8; i++, j -= 10) {
    items << i + j
}
assert items == [73, 64, 55, 46, 37]

// B
for ({ List items2 = []; int i = 3; long j = 70 }(); i < 8; i++, j -= 10) {    
// note multiple types
    items2 << i + j
}
assert items2 == [73, 64, 55, 46, 37]

// C
items.clear()
for (int i = 3, j = 70; { println i; i < 8 }(); i++, j -= 10) {     // prints 3 
-> 8
    items << i + j
}
assert items == [73, 64, 55, 46, 37]

// D
items.clear()
for ((i, j)=[3, 70]; i < 8; { i++; j -= 10; println '*' }()) {     // prints * 
five times
    items << i + j
}
assert items == [73, 64, 55, 46, 37]
{code}
I think it is worth keeping. It worries me that we don't have any tests cases 
covering these cases.

> remove support for expression list in for-each statement
> --------------------------------------------------------
>
>                 Key: GROOVY-11601
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11601
>             Project: Groovy
>          Issue Type: Improvement
>          Components: parser-antlr4
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Minor
>
> The for-each loop supports an arbitrary expression list.  Presumably this is 
> for legacy reasons.  Now that multi-variable declaration is supported by 
> for-each and classic for, it does not seem necessary to support expression 
> list.  I propose to remove it from the parser grammar.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to