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

Fail to infer the correct type argument when having conditionals and diamond operator

    XMLWordPrintableJSON

Details

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

    Description

      I think this is a regression bug, because Groovy 4.0.2 compiles the program successfully.

      class Foo<T> {}
      
      class Test {
        public static void test() {
          foo((true) ? new Foo<Boolean>() : new Foo<>());
          
        }
      
        public static void foo(Foo<Boolean> x) {}
        
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 5: [Static type checking] - Cannot call Test#foo(Foo<java.lang.Boolean>) with arguments [Foo<? extends java.lang.Object>]
       @ line 5, column 5.
             foo((true) ? new Foo<Boolean>() : new Foo<>());
             ^
      
      1 error
      

      Expected Behaviour

      Compile successfully

      Tested against master (commit: e183dc8e04a8ca8762e85e21ac3ee0c03138b6e1)

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: