Flow analysis: Add ID test cases for #46937.

Bug: https://github.com/dart-lang/sdk/issues/46937
Change-Id: Ic1073a4514ab59468881b6b641bf179187103140
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211041
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2021-08-24 21:00:04 +00:00 committed by commit-bot@chromium.org
parent a81945ed5c
commit 389740cff9

View file

@ -0,0 +1,47 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class C {
C method(dynamic value) => this;
C Function(dynamic) get functionGetter => (_) => this;
}
void methodCall(C? c) {
c?.method(/*nonNullable*/ c);
}
void functionGetterCall(C? c) {
c?.functionGetter(/*nonNullable*/ c);
}
void methodCall_nullShorting(C? c) {
c?.method(/*nonNullable*/ c).method(/*nonNullable*/ c);
}
void functionGetterCall_nullShorting(C? c) {
c?.functionGetter(/*nonNullable*/ c).functionGetter(/*nonNullable*/ c);
}
void null_aware_cascades_promote_target(C? c) {
c?..method(/*nonNullable*/ c);
c?..functionGetter(/*nonNullable*/ c);
}
void null_aware_cascades_do_not_promote_others(C? c, int? i) {
// Promotions that happen inside null-aware cascade sections
// disappear after the cascade section, because they are not
// guaranteed to execute.
c?..method(i!);
c?..functionGetter(i!);
i;
}
void normal_cascades_do_promote_others(C c, int? i, int? j) {
// Promotions that happen inside non-null-aware cascade sections
// don't disappear after the cascade section.
c..method(i!);
c..functionGetter(j!);
/*nonNullable*/ i;
/*nonNullable*/ j;
}