mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 20:51:19 +00:00
Fix issue 22875
Allocate temp variables of let nodes in the async temp scope instead of the preamble. R=srdjan@google.com Review URL: https://codereview.chromium.org//1017753003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44547 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
8fba9fa5a4
commit
c3418f1e63
|
@ -601,12 +601,13 @@ void AwaitTransformer::VisitAssignableNode(AssignableNode* node) {
|
|||
|
||||
|
||||
void AwaitTransformer::VisitLetNode(LetNode* node) {
|
||||
// Add all the initializer nodes and their temporary variables
|
||||
// to the preamble. The temporary variables will be captured
|
||||
// as a side effect of being added to a scope, and the subsequent
|
||||
// nodes that are added to the preample can access them.
|
||||
// Add all the initializer nodes to the preamble and the
|
||||
// temporary variables to the scope for async temporary variables.
|
||||
// The temporary variables will be captured as a side effect of being
|
||||
// added to a scope, and the subsequent nodes that are added to the
|
||||
// preample can access them.
|
||||
for (intptr_t i = 0; i < node->num_temps(); i++) {
|
||||
preamble_->scope()->AddVariable(node->TempAt(i));
|
||||
function_top_->AddVariable(node->TempAt(i));
|
||||
AstNode* new_init_val = Transform(node->InitializerAt(i));
|
||||
preamble_->Add(new(Z) StoreLocalNode(node->token_pos(),
|
||||
node->TempAt(i),
|
||||
|
|
|
@ -31,12 +31,24 @@ sum(a) async {
|
|||
return s;
|
||||
}
|
||||
|
||||
// Adapted from repro case for issue 22875.
|
||||
sum2(n) async {
|
||||
int i, s = 0;
|
||||
for (i = 1; i <= n; await i++) {
|
||||
// The loop-local variable j was necessary for the crash in 22785.
|
||||
var j = await i;
|
||||
s += j;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
test() async {
|
||||
Expect.equals(10, await post0(10));
|
||||
Expect.equals(21, await post1(10));
|
||||
Expect.equals(11, await pref0(10));
|
||||
Expect.equals(23, await pref1(10));
|
||||
Expect.equals(10, await sum([1, 2, 3, 4]));
|
||||
Expect.equals(10, await sum2(4));
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
Loading…
Reference in a new issue