Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
Consider the following:
class C { // implicitly Iterable<String> Iterator<String> iterator() {} // sometimes supplied via DGM } @TypeChecked void test(C c) { for (string in c) { string.toUpperCase() } }
If "@TypeChecked" is removed, this works. STC cannot determine the loop element type – see StaticTypeCheckingVisitor#inferLoopElementType and compare with inferComponentType which runs for spread.
GROOVY-10476 describes the use case in more detail.
Attachments
Issue Links
- is related to
-
GROOVY-10712 STC: for-each over Iterator fails to infer element type
- Closed
-
GROOVY-8133 Static type checking failure for streams and spread operator
- Closed
-
GROOVY-10476 STC: for-each loop on iterable-like types
- Closed
- relates to
-
GROOVY-11335 STC: for loop element type inference with multiple instanceof
- Closed