Closed scheglov closed 4 years ago
See also https://github.com/dart-lang/sdk/issues/39865 and https://github.com/dart-lang/sdk/issues/40088 I will keep the issue for the analyzer open for now, because I don't remember this code, and don't know if we do such promotion intentionally.
I believe that warnings are correct. After a = new A() the variable a is promoted from A? to A. So, null checking on it is a warning.
a = new A()
a
A?
A
--- Command "dart2analyzer" (took 18ms): DART_CONFIGURATION=ReleaseX64NNBD out/ReleaseX64NNBD/dart-sdk/bin/dartanalyzer --enable-experiment=non-nullable --ignore-unrecognized-flags --packages=/b/s/w/ir/cache/builder/sdk/.packages --format=machine --no-hints /b/s/w/ir/cache/builder/sdk/tests/co19/src/LanguageFeatures/nnbd/static_errors_A14_t08.dart exit code: 0 stderr: WARNING|STATIC_WARNING|INVALID_NULL_AWARE_OPERATOR|/b/s/w/ir/cache/builder/sdk/tests/co19/src/LanguageFeatures/nnbd/static_errors_A14_t08.dart|33|4|3|The target expression can't be null, so the null-aware operator '?.[' can't be used. WARNING|STATIC_WARNING|INVALID_NULL_AWARE_OPERATOR|/b/s/w/ir/cache/builder/sdk/tests/co19/src/LanguageFeatures/nnbd/static_errors_A14_t08.dart|31|4|2|The target expression can't be null, so the null-aware operator '?.' can't be used. WARNING|STATIC_WARNING|INVALID_NULL_AWARE_OPERATOR|/b/s/w/ir/cache/builder/sdk/tests/co19/src/LanguageFeatures/nnbd/static_errors_A14_t08.dart|32|5|3|The target expression can't be null, so the null-aware operator '?..' can't be used. --- Re-run this test: python tools/test.py -n analyzer-asserts-strong-linux co19/LanguageFeatures/nnbd/static_errors_A14_t08
The spec for flow analysis, look for "promotable via assignment".
Thank you!
See also https://github.com/dart-lang/sdk/issues/39865 and https://github.com/dart-lang/sdk/issues/40088 I will keep the issue for the analyzer open for now, because I don't remember this code, and don't know if we do such promotion intentionally.
I believe that warnings are correct. After
a = new A()
the variablea
is promoted fromA?
toA
. So, null checking on it is a warning.