Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.0-beta-1
-
None
-
OpenJDK 8
Description
The following code fails to compile when STC is enabled:
import java.util.concurrent.ConcurrentHashMap; class Test { public void test() { Set<Integer> integers = ConcurrentHashMap.newKeySet(); integers.add(1); integers.add(2); printSet(integers); } private void printSet(Set<Integer> integers) { println "$integers"; } }
The error reported by the compiler is:
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script_a26d7b8defa71ea9b230673f8bc53d80.groovy: 9: [Static type checking] - Cannot call Test#printSet(java.util.Set<java.lang.Integer>) with arguments [java.util.concurrent.ConcurrentHashMap$KeySetView<java.lang.Object, java.lang.Object>] @ line 9, column 9. printSet(integers); ^
This issue is new to 4.0.0-beta-1, it has not been observed before that. It looks like the variable definition is treated as if it was def integers so the generic type of the Set is not correctly resolved.