-
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.
[dart2js] Include block statements as potentially captured scopes.
Some scopes that are capturable by closures are not getting marked as such. Instead the parent scope (e.g. the enclosing member) is being treated as the captured scope that owns all the variable declarations down to the closure. The scopes are then being shared across different closures and variables with the same name are able to be overwritten. This bug occurs for any block that isn't a loop or function (i.e. raw blocks, if blocks, try blocks). Loops are correctly handled as defining a scope and therefore those already work correctly. Note: This may cause some small code size increase. There may now be extra assignements reseting capture boxes in more scopes. Bug: #59843 Change-Id: Ic5009188795daabc1544f703fbeca01c0f1951d9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403263 Commit-Queue: Nate Biggs <natebiggs@google.com> Reviewed-by: Stephen Adams <sra@google.com>
- Loading branch information
Showing
7 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,64 @@ | ||
import 'package:expect/expect.dart'; | ||
|
||
void testBlock() { | ||
List<void Function()> functions = []; | ||
{ | ||
var sub; | ||
functions.add(() { | ||
Expect.isNull(sub); | ||
sub = 1; | ||
}); | ||
} | ||
{ | ||
var sub; | ||
functions.add(() { | ||
Expect.equals(sub, 2); | ||
}); | ||
sub = 2; | ||
} | ||
for (var function in functions) function(); | ||
} | ||
|
||
void testIf() { | ||
List<void Function()> functions = []; | ||
if ('1234'.length > 2) { | ||
var sub; | ||
functions.add(() { | ||
Expect.isNull(sub); | ||
sub = 1; | ||
}); | ||
} | ||
if ('1234'.length > 2) { | ||
var sub; | ||
functions.add(() { | ||
Expect.equals(sub, 2); | ||
}); | ||
sub = 2; | ||
} | ||
for (var function in functions) function(); | ||
} | ||
|
||
void testTry() { | ||
List<void Function()> functions = []; | ||
try { | ||
var sub; | ||
functions.add(() { | ||
Expect.isNull(sub); | ||
sub = 1; | ||
}); | ||
} catch (e) {} | ||
try { | ||
var sub; | ||
functions.add(() { | ||
Expect.equals(sub, 2); | ||
}); | ||
sub = 2; | ||
} catch (e) {} | ||
for (var function in functions) function(); | ||
} | ||
|
||
void main() { | ||
testBlock(); | ||
testIf(); | ||
testTry(); | ||
} |