Fix incorrect nullability inference for ??

Fix bug where (a?.foo) was being incorrectly inferred to be
non-nullable if `foo` was non-nullable.

BUG=
R=jmesserly@google.com

Review-Url: https://codereview.chromium.org/2996523003 .
This commit is contained in:
Leaf Petersen 2017-08-04 15:30:54 -07:00
parent df3110df54
commit d3344ed466
10 changed files with 20 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -59,7 +59,8 @@ abstract class NullableTypeInference {
// resulting value if that becomes an issue, so we maintain the invariant
// that each node is visited once.
Element element = null;
if (expr is PropertyAccess) {
if (expr is PropertyAccess &&
expr.operator?.type != TokenType.QUESTION_PERIOD) {
element = expr.propertyName.staticElement;
} else if (expr is Identifier) {
element = expr.staticElement;

View file

@ -79,10 +79,20 @@ class Foo {
Foo(this._bar) : str = _bar?.s;
}
// Check that ?? isn't incorrectly optimized as non-nullable
// (DDC regression test)
test3() {
List n = null;
var func = n?.add;
var result = func ?? 1;
Expect.equals(result, 1);
}
main() {
for (int i = 0; i < 10; i++) {
test();
test2();
test3();
}
Expect.equals(null, new Foo(new Bar()).str);