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.
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.