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

Incompatible generic argument types when mixing diamond operator in parameterized function

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      This might be a regression, as Groovy 4.0.10 accepts the program.

      I have the following program

      import java.util.*;
      
      class Main {
        static final void test() {
          Map<Number, String> x = null;
          Map<Number, String> y = Collections.unmodifiableNavigableMap(new TreeMap<>(x));
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 6: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.NavigableMap<java.lang.Object, java.lang.Object> to: java.util.Map<java.lang.Number, java.lang.String>
       @ line 6, column 29.
             Map<Number, String> y = Collections.unmodifiableNavigableMap(new TreeMap<>(x));
                                     ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Attachments

        Activity

          People

            Unassigned Unassigned
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: