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

Incomplete type variable substitution when using wildcard type and diamond operator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.2
    • None
    • None

    Description

      I have the following groovy program

      class Foo<T> {
        Foo(T x) {}
      }
      
      class Bar<T> {
        Bar(Foo<? extends T> foo, T p) {
      
        }
      
        T m(T x) {
          return null;
        }
      }
      
      public class Test<T>  {
        void test() {
          T x = null;
          new Bar<>(new Foo<T>(x), x).m(x);
        }  
      }
      

      Actual behaviour

      groovyc rejects the program by raising

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 20: [Static type checking] - Cannot find matching method Bar#m(T). Please check if the declared type is correct and if the method exists.
       @ line 20, column 5.
             new Bar<>(new Foo<T>(x), x).m(x);
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully.

      The bug happens when:

      • The constructor of `Bar` expects a parameterized type containing a wildcard type (i.e., `Foo<? extends T>`
      • The constructor of `Bar` expects something of type `T` (i.e., `T p`).

      Tested against master (commit: 85676f1855bbe751bac897ea3fdd900fbbe74ecb).

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: