Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Consider the following:
@groovy.transform.TypeChecked void test(obj) { if (obj instanceof Collection) { if (obj instanceof Serializable) { for (item in obj) { println item } } } }
The inferred type of "obj" is (Collection & Serializable). The loop element check fails with:
java.lang.UnsupportedOperationException at org.codehaus.groovy.transform.stc.UnionTypeClassNode.getComponentType(UnionTypeClassNode.java:232) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferLoopElementType(StaticTypeCheckingVisitor.java:2042) at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitForLoop(StaticTypeCheckingVisitor.java:2008) at org.codehaus.groovy.ast.stmt.ForStatement.visit(ForStatement.java:47)
Attachments
Issue Links
- is related to
-
GROOVY-11305 STC: support for-each or for-in loop for implicitly-Iterable type
- Closed