mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:31:58 +00:00
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:
parent
df3110df54
commit
d3344ed466
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
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue