Eric Milles created GROOVY-11335: ------------------------------------ Summary: STC: for loop element type inference with multiple instanceof Key: GROOVY-11335 URL: https://issues.apache.org/jira/browse/GROOVY-11335 Project: Groovy Issue Type: Bug Components: Static Type Checker Reporter: Eric Milles Assignee: Eric Milles
Consider the following: {code:groovy} @groovy.transform.TypeChecked void test(obj) { if (obj instanceof Collection) { if (obj instanceof Serializable) { for (item in obj) { println item } } } } {code} The inferred type of "obj" is (Collection & Serializable). The loop element check fails with: {code} 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) {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)