(Parent issue #44897)
As of a42244f, I've begun implementing "why not promoted" functionality in the CFE. For example, this code:
f(int? i, int? j) {
if (i == null) return;
i = j;
i.isEven;
}
main() {
f(null, null);
}
leads to the following output:
../../tmp/test.dart:4:5: Error: Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
Try accessing using ?. instead.
i.isEven;
^^^^^^
../../tmp/test.dart:3:3: Context: Variable 'i' could be null due to a write occurring here.
Try null checking the variable after the write.
i = j;
^
I tried to write a language test to validate this functionality (see https://dart-review.googlesource.com/c/sdk/+/182901) but test.py currently only supports testing the main error message; it ignores the "Context:" messages entirely. We need a way to test the context messages as well.
(Eventually we'll want to extend these tests to support analyzer as well, but some analyzer work needs to be done first, to get the context messages exposed in a machine readable way, so it makes sense to start with CFE support).
(Parent issue #44897)
As of a42244f, I've begun implementing "why not promoted" functionality in the CFE. For example, this code:
leads to the following output:
I tried to write a language test to validate this functionality (see https://dart-review.googlesource.com/c/sdk/+/182901) but test.py currently only supports testing the main error message; it ignores the "Context:" messages entirely. We need a way to test the context messages as well.
(Eventually we'll want to extend these tests to support analyzer as well, but some analyzer work needs to be done first, to get the context messages exposed in a machine readable way, so it makes sense to start with CFE support).