As per the following issue:

https://issues.apache.org/jira/browse/GROOVY-8882

I'm planning to change the inferred type for the loop variable to be a bit
smarter and more consistent.

Current behavior:

// code             inferred type with CS     without CS
for (s in 'abc')               Character     String
for (String s in 'abc')        Character     String
for (Character c in 'abc')     Character     Character

Planned behavior:

// code            inferred type with CS     without CS
for (s in 'abc')                  String     String
for (String s in 'abc')           String     String
for (Character c in 'abc')     Character     Character

The same change automatically applies to the ':' variant of the for loop.
This also makes the for loop closer to the internal iterators, e.g. each.
(We have an existing gap between dynamic/@CompileStatic when the closure
arg is explicitly made a character. I think that can be looked at as a
separate issue.)

Further details:

https://github.com/apache/groovy/pull/827

Cheers, Paul.

Reply via email to