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

Incompatible generic argument type when combining conditionals and bounded type parameters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.11, 4.0.3
    • Static Type Checker
    • None

    Description

      I have the following program

      class Foo<X> {}
      
      class Test {
      
        public static <T extends Foo<Number>> T test() {
          T x = (T) null;
          T y = (true) ? x : (T) null;
          y
        }
      }
      

      Actual behaviour

      The compiler rejects the program with

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 8: [Static type checking] - Incompatible generic argument types. Cannot assign Foo<java.lang.Object> to: T
       @ line 8, column 5.
             y
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      *NOTE:* This bug occurs only when `test` and `Foo` have type parameters with different names.

      Tested against master (commit: 5c468cd352f37fb5c599a3f51534ffcc55b339ed).

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: