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

Type argument inference does not work in ternary operator

    XMLWordPrintableJSON

    Details

      Description

      I have the following Groovy program.

      @groovy.transform.CompileStatic
      public class Test {
        public static void main(String[] args) {
            final A<B> x = (true ? new A<>(new B()): new A<>(new C()))
            bar(x) // compiles
            bar((true ? new A<>(new B()): new A<>(new C()))) // does not compile
        }
      
        public static void bar(A<B> x) {}
      }
      
      class A<T> {
        T f;
        public A(T f) {
          this.f = f;
        }
      }
      
      
      class B {}
      class C extends B{}
      
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Test.groovy: 6: [Static type checking] - Cannot call Test#bar(A <B>) with arguments [A <? extends B>]
       @ line 6, column 7.
               bar((true ? new A<>(new B()): new A<>(new C())))
               ^
      
      1 error
      
      

      Expected Behavior

      Compile successfully.

      Comment

      This should be a regression bug because it compiles with the 4.0.0-alpha-2 compiler.

      Affected Version

      This programs fails when compiled with the compiler from the master (commit: f0eea862549529ef4e93fafe337f86dd4ac98751).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              schaliasos Stefanos Chaliasos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: