-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Field promotion: add a test case to repro #52728.
BUG: #52728 Change-Id: I95be48b923ad84b725eac5099db11207d46a74b5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313181 Auto-Submit: Paul Berry <paulberry@google.com> Commit-Queue: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
- Loading branch information
1 parent
0ff8d76
commit 0c9cf2a
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
tests/language/inference_update_2/cascaded_field_promotion_unstable_target_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
// Tests that if a field of an unstable target is promoted within a cascade | ||
// expression, that promotion isn't over-applied to uses of the field within | ||
// subsequent cascades. | ||
|
||
// SharedOptions=--enable-experiment=inference-update-2 | ||
|
||
import '../static_type_helper.dart'; | ||
|
||
class C { | ||
D get d => D(E()); // Unstable | ||
} | ||
|
||
class D { | ||
final E? _e; // Promotable | ||
D(this._e); | ||
} | ||
|
||
class E { | ||
void f() {} | ||
} | ||
|
||
void test(C c) { | ||
// The value of `c.d` is cached in a temporary variable, call it `t0`. | ||
((c.d) | ||
// `t0._e` could be null at this point. | ||
.._e.expectStaticType<Exactly<E?>>() | ||
// This `!` operator ensures that `t0._e` is not null. | ||
.._e!.f() | ||
// Therefore, `t0._e` is now promoted. | ||
.._e.expectStaticType<Exactly<E>>()) | ||
// This `._e` also refers to `t0._e`, so it is promoted too. | ||
._e | ||
.expectStaticType<Exactly<E>>(); | ||
// Now, a new value of `c.d` is computed, and cached in a new temporary | ||
// variable, call it `t1`. | ||
((c.d) | ||
// Even though we are in a cascade, and field promotions of unstable targets | ||
// are allowed inside a cascade, the promotion above is not retained, | ||
// because there's no guarantee that `t0` and `t1` refer to the same | ||
// instance of `D`. | ||
.._e.expectStaticType<Exactly<E?>>() | ||
// However, a new promotion can still be done: | ||
.._e!.f() | ||
// And now the new promotion is in effect. | ||
.._e.expectStaticType<Exactly<E>>()) | ||
._e | ||
.expectStaticType<Exactly<E>>(); | ||
} | ||
|
||
main() { | ||
test(C()); | ||
} |