Conditional expression mistakenly treated as standalone

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 17
    • Affects Version/s: 8u101, 9, 10
    • Component/s: tools
    • None
    • b20

      This test produces 3 unexpected type errors:

          static class Outer {
              class Inner<T> implements Runnable { public void run() {} }
          }

          void test(Outer outer) {
              Outer.Inner<String> inner1 = outer.new Inner<>(); // ok
              Outer.Inner<String> inner2 = test ? outer.new Inner<>() : null; // error
              Outer.Inner<String> inner3 = test ? null: outer.new Inner<>(); // error
              Outer.Inner<String> inner4 = test ? outer.new Inner<String>() : outer.new Inner<>(); // error
          }
          
      The conditional expressions are treated as standalone, despite appearing in an assignment context. So the diamond instance creation always infers Inner<Object>, not Inner<String>.

      Some initial testing seems to trace the issue to a false positive coming from Attr.isBooleanOrNumeric.

            Assignee:
            Guoxiong Li
            Reporter:
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: