Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0.0
-
Fix Version/s: 2.0.1
-
Component/s: Static compilation
-
Labels:None
-
Environment:Ubuntu 12.04, Oracle JVM 1.7.0_05
-
Testcase included:yes
-
Number of attachments :
Description
import groovy.transform.CompileStatic @CompileStatic class BrokenCompileStaticTest extends GroovyTestCase { void testMapForEachAttribute() { def result = "" def sum = 0 for ( Map.Entry<String, Integer> it in [a:1, b:3].entrySet() ) { result += it.key sum += it.value } assert result == "ab" assert sum == 4 } }
fails to infer the type of Map.Entry#key and #value, regardless of the proper generic type in the for-in loop definition.
Message:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /home/steven/BrokenCompileStaticTest.groovy: 9: [Static type checking] - Cannot find matching method int#plus(java.lang.Object <V>) @ line 9, column 8. sum += it.value ^ 1 error
Also, shouldn't groovy report both static type errors, instead of just the first?
Issue Links
- depends upon
-
GROOVY-5594
Type checker doesn't infer property type if coming from a generified getter
-
-
GROOVY-5595
Type checker doesn't fully infer Map.Entry type
-
Oh, on second look, groovy only fails to infer the type of Map.Entry#value. weird.