Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8200145

Conditional expression mistakenly treated as standalone

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u101, 9, 10
    • Fix Version/s: tbd_minor
    • Component/s: tools
    • Labels:
      None

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              dlsmith Dan Smith
              Reporter:
              dlsmith Dan Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: