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

Issue with the diamond operator and conditional

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      class A<T extends Number> {
        T foo() {
          T x = null;
          (true) ?
            new B<>(x).f: new B<>(x).f
        }
      }
      class B<X> {
        X f;
        B(X x) {
          this.f = f;
        }
      }
      

      Actual behaviour

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

      Expected Behaviour

      Compile successfuly

       

      Tested against master (https://github.com/apache/groovy/commit/2a97313250875d60df82302f31d77dd7f07ae685)

       

      I think this is related to https://issues.apache.org/jira/browse/GROOVY-10226. So I close this.

      Attachments

        Activity

          People

            Unassigned Unassigned
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: