Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.5
-
None
Description
The following fails to compile with Groovy 4.0.5:
import java.util.function.BiFunction @groovy.transform.CompileStatic class MapTransformEntries { private static <K, V1, V2> Map<K, V2> transformEntries(Map<K, V1> map, BiFunction<? super K, ? super V1, V2> transformer) { throw new UnsupportedOperationException("implementation not relevant"); } { Map<String, ? extends File> outputFiles Map<String, Integer> outputFileSpecs = transformEntries(outputFiles, { key, value -> value.hashCode() }) } }
Producing result:
1 compilation error: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.Map<? extends java.lang.Object, java.lang.Integer> to: java.util.Map<java.lang.String, java.lang.Integer> at line: 11, column: 48
At first glance, this seems similar to GROOVY-10613 and some of its related issues.
We can workaround by casting the above to Map<String, Integer>, but this was not necessary in Groovy 3.x.
Thanks to otogami for creating the reproducer
Attachments
Issue Links
- is caused by
-
GROOVY-9998 Wildcards with a lower bound fail static type checking
- Closed