Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
4.0.2
-
None
-
None
Description
The following code can not run when STC is enabled:
import java.util.stream.Collectors; @groovy.transform.CompileStatic def m() { Map<String, Integer> map = new HashMap<>(); map.put("a", 1); map.put("b", 2); final Map<String, Integer> result = map.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v1)); return result; } assert [a:1, b:2] == m();
Here are the error messages:
3 compilation errors: [Static type checking] - Cannot find matching method java.lang.Object#getKey(). Please check if the declared type is correct and if the method exists. at line: 10, column: 67 [Static type checking] - Cannot find matching method java.lang.Object#getValue(). Please check if the declared type is correct and if the method exists. at line: 10, column: 84 [Static type checking] - Incompatible generic argument types. Cannot assign java.util.Map<java.lang.Object, java.lang.Object> to: java.util.Map<java.lang.String, java.lang.Integer> at line: 10, column: 13
Attachments
Issue Links
- duplicates
-
GROOVY-10054 STC: Cannot infer lambda parameter types for a stream collector
- Open
-
GROOVY-10047 STC infers Closure instead of SAM for method references
- Closed
-
GROOVY-10544 Static compiler chooses superinterface return type
- Closed