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

Incompatible generic argument when mixing diamond operator and "super" wildcard

    XMLWordPrintableJSON

Details

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

    Description

      Somewhat related to GROOVY-11254.

      I have the following program

      import java.util.function.*;
      
      class Foo<T> {
        Foo(Supplier<? super T> x) {}
      }
      
      class Main {
        static final void test() {
          Supplier<CharSequence> func = null;
          Foo<StringBuffer> x = new Foo<>(func);
      
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 10: [Static type checking] - Incompatible generic argument types. Cannot assign Foo<java.lang.CharSequence> to: Foo<java.lang.StringBuffer>
       @ line 10, column 27.
             Foo<StringBuffer> x = new Foo<>(func);
                                   ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Notes

      Tested against master

      Test case adapted from:

      class Main {
        static final void test() {
          final org.apache.commons.collections4.functors.NotPredicate<CharSequence> x = null;
          final org.apache.commons.collections4.functors.PredicateDecorator<StringBuffer> y = new org.apache.commons.collections4.functors.NullIsTruePredicate<>(x);
        }
      }
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: