Skip to content

Commit 36e89f8

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Flow analysis: ensure that restrict method doesn't try to promote write-captured variables.
Fixes #42066 Change-Id: Ieab80c004b3d331abb81916c3e158416bcd3ce86 Bug: #42066 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153480 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 653e444 commit 36e89f8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,10 @@ class VariableModel<Variable, Type> {
18041804
bool newUnassigned = unassigned && otherModel.unassigned;
18051805
bool newWriteCaptured = writeCaptured || otherModel.writeCaptured;
18061806
List<Type> newPromotedTypes;
1807-
if (unsafe) {
1807+
if (newWriteCaptured) {
1808+
// Write-captured variables can't be promoted
1809+
newPromotedTypes = null;
1810+
} else if (unsafe) {
18081811
// There was an assignment to the variable in the "this" path, so none of
18091812
// the promotions from the "other" path can be used.
18101813
newPromotedTypes = thisPromotedTypes;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
f() {
6+
num par2;
7+
par2 = 0;
8+
if (par2 is! int) return;
9+
try {} catch (exception) {
10+
throw 'x';
11+
() {
12+
par2 = 1;
13+
};
14+
} finally {}
15+
}

0 commit comments

Comments
 (0)