-
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.
[stable][dart2js] Fix late local lowering with record destructuring.
The CFE's lowering for record patterns can sometimes make use of late local fields. Dart2JS's late lowerer assumes that all late local fields live in the scope of some function body. Record patterns allow late locals to be created in other contexts though. Some examples that break this assumption include field initializers and expressions in constructor initializer lists. To fix this we add a late local scope in some extra contexts where these record patterns can show up. Fixes: 53358 Bug: #53358 Change-Id: Ic730f41253782241b3394c0b0353d1731e122c85 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/323020 Cherry-pick-request: #53449 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324600 Reviewed-by: Sigmund Cherem <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
- Loading branch information
Showing
4 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2023, 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. | ||
|
||
List<(int,)> records = [(1,), (2,)]; | ||
|
||
// Library field initializer | ||
Map<int, int> topLevel = {for (final (int x,) in records) x: x}; | ||
|
||
class Bar { | ||
final Map<int, int> bar; | ||
|
||
Bar(this.bar); | ||
} | ||
|
||
class Foo extends Bar { | ||
// Class field initializer | ||
final Map<int, int> foo1 = {for (final (int x,) in records) x: x}; | ||
final Map<int, int> foo2; | ||
Foo() | ||
// Constructor field initializer | ||
: foo2 = {for (final (int x,) in records) x: x}, | ||
// Super initializer | ||
super({for (final (int x,) in records) x: x}); | ||
} | ||
|
||
void main() { | ||
print(topLevel); | ||
final foo = Foo(); | ||
print(foo.foo1); | ||
print(foo.foo2); | ||
print(foo.bar); | ||
} |