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

LUB does not work correctly in case of ternary operator

    XMLWordPrintableJSON

Details

    Description

      I have the following program

       

      class Foo {
        public String x = "f";
      }
      
      class A<T> {
        public T f;
        A(T f) {
          this.f = f;
        }
      }
      public class Main {
        public static void foo() {
          def temp;
          if (true) {
            temp = new A<>(new Foo());
          } else {
            temp = new A<>(new Foo());
          }
          temp.f.x.toLowerCase() // works  fine
        }
      
        public static void bar() {
          A<Foo> temp = true ? new A<>(new Foo()) : new A<>(new Foo())
          temp.f.x // does not compile;
        }
      }
      

       

      Actual Behaviour

      I get the following compile-time error

       

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 26: [Static type checking] - No such property: x for class: java.lang.Object
       @ line 26, column 5.
             temp.f.x // does not compile;
             ^1 error
      
      

      Expected Behaviour

      Compile Successfuly.

       

      Tested on https://github.com/apache/groovy/commit/06e8cdeac2aa84403506b23a22c5254c5219850b

       

       

      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:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h