You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/05/31 22:34:00 UTC
[jira] [Assigned] (GROOVY-11050) Unable to construct Map with repeating key/value entries
[ https://issues.apache.org/jira/browse/GROOVY-11050?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-11050:
------------------------------------
Assignee: Eric Milles
> 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
> Assignee: Eric Milles
> Priority: Minor
>
> 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)