Kyle Moore created GROOVY-10765:
-----------------------------------
Summary: STC: Closure implementation of Java @FunctionalInterface
loses type information
Key: GROOVY-10765
URL: https://issues.apache.org/jira/browse/GROOVY-10765
Project: Groovy
Issue Type: Bug
Components: Static compilation, Static Type Checker
Affects Versions: 4.0.5
Reporter: Kyle Moore
The following fails to compile with Groovy 4.0.5:
{code:groovy}
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() })
}
}
{code}
Producing result:
{noformat}
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
{noformat}
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
--
This message was sent by Atlassian Jira
(v8.20.10#820010)