Thodoris Sotiropoulos created GROOVY-11050:
----------------------------------------------
Summary: Unable to construct Map with repeating key/value entries
Key: GROOVY-11050
URL: https://issues.apache.org/jira/browse/GROOVY-11050
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Thodoris Sotiropoulos
I have the following program
{code}
class Main {
static final <V> void test() {
V key = null;
CharSequence value = null;
java.util.Map.of(key, value); // succeeds
java.util.Map.of(key, value, key, value); // fails
}
}
{code}
h3. Actual behavior
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 6: [Static type checking] - Cannot call <K,V> java.util.Map#of(K,
V, K, V) with arguments [V, java.lang.CharSequence, V, java.lang.CharSequence]
@ line 6, column 5.
java.util.Map.of(key, value, key, value);
^
1 error
{code}
h3. Expected behavior
Compile successfully
h3. Notes
Tested against master (commit: 7a4b2679c77aea8cd9dc00fa2d3b71e25e97fbd2)
The bug is triggered when the variable key has type "V".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)