Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 41907fd

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: clarify when variables are removed from the "promoted" map.
Change-Id: I72fe7d59ccce0dea507af63e1d7910ade8325544 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110241 Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent fdfad8d commit 41907fd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/front_end/lib/src/fasta/flow_analysis/flow_analysis.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,17 @@ class State<Variable, Type> {
718718

719719
/// For each variable whose type is promoted at this point in the control
720720
/// flow, the promoted type. Variables whose type is not promoted are not
721-
/// present in the map. Variables that have gone out of scope are not
722-
/// guaranteed to be present in the map even if they were promoted at the time
723-
/// they went out of scope.
721+
/// present in the map.
722+
///
723+
/// Flow analysis has no awareness of scope, so variables that are out of
724+
/// scope are retained in the map until such time as their promotions would
725+
/// have been lost, if their scope had extended to the entire function being
726+
/// analyzed. So, for example, if a variable is declared and then promoted
727+
/// inside the `then` branch of an `if` statement, and the `else` branch of
728+
/// the `if` statement ends in a `return` statement, then the promotion
729+
/// remains in the map after the `if` statement ends. This should not have
730+
/// any effect on analysis results for error-free code, because it is an error
731+
/// to refer to a variable that is no longer in scope.
724732
final Map<Variable, Type> promoted;
725733

726734
/// Creates a state object with the given [reachable] status. All variables

0 commit comments

Comments
 (0)