You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Paul King <pa...@asert.com.au> on 2018/11/21 04:38:47 UTC

GROOVY-8882: Inferred type for String in for loop

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.

Re: GROOVY-8882: Inferred type for String in for loop

Posted by Daniel Sun <re...@hotmail.com>.
+1

Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html