Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11050

Unable to construct Map with repeating key/value entries

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      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
        }
      }
      

      Actual behavior

      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
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: 7a4b2679c77aea8cd9dc00fa2d3b71e25e97fbd2)

      The bug is triggered when the variable key has type "V".

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: