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

LUB is computed incorrectly when involving bounded type variables

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.2
    • Static Type Checker
    • None

    Description

      I have the following program:
       

      class Foo<T> {}
      class Main {
        static final <T extends Foo<String>> T test() {
          final T x = null;
          true ? (T) null: x
        }
      }
      

      Actual behaviour

      groovyc rejects the above program and produces

       

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 6: [Static type checking] - Cannot return value of type Foo<java.lang.Object> on method returning type T
       @ line 6, column 5.
             true ? (T) null: x
             ^1 error
      
      

      Expected behaviour

      Compile successfully

      Note that if I replace the bound of type parameter `T` with a non-parameterized bound (e.g., Number), groovyc compiles the program as expected.
       
      Tested against master
       

       

       

      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: