Skip to content

Commit

Permalink
Flow analysis: ensure that restrict method doesn't try to promote w…
Browse files Browse the repository at this point in the history
…rite-captured variables.

Fixes #42066

Change-Id: Ieab80c004b3d331abb81916c3e158416bcd3ce86
Bug: #42066
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
  • Loading branch information
stereotype441 authored and commit-bot@chromium.org committed Jul 8, 2020
1 parent 653e444 commit 36e89f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,10 @@ class VariableModel<Variable, Type> {
bool newUnassigned = unassigned && otherModel.unassigned;
bool newWriteCaptured = writeCaptured || otherModel.writeCaptured;
List<Type> newPromotedTypes;
if (unsafe) {
if (newWriteCaptured) {
// Write-captured variables can't be promoted
newPromotedTypes = null;
} else if (unsafe) {
// There was an assignment to the variable in the "this" path, so none of
// the promotions from the "other" path can be used.
newPromotedTypes = thisPromotedTypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2020, 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.

f() {
num par2;
par2 = 0;
if (par2 is! int) return;
try {} catch (exception) {
throw 'x';
() {
par2 = 1;
};
} finally {}
}

0 comments on commit 36e89f8

Please sign in to comment.