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

Type variable substitution does not work well when running into chain of field accesses

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class Foo<T> {
        T foo() {
          new Bar<T>().f1.f2.f3;
        }
        
      }
      
      class Bar<Y> {
        Baz<Y> f1;
      }
      
      class Baz<T> {
        Qux<T> f2;
      }
      
      class Qux<X> {
        X f3;
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 3: [Static type checking] - Cannot return value of type Y on method returning type T
       @ line 3, column 5.
             new Bar<T>().f1.f2.f3;
             ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Tested against master (https://github.com/apache/groovy/commit/0e8d0e26e3fe4f8cc21d58f1a1163ae29a8892db)

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: