groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject GROOVY-8882: Inferred type for String in for loop
Date Wed, 21 Nov 2018 04:38:47 GMT
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.

Mime
View raw message