-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dart2js
crashes on extension with records and type arguments
#53358
Comments
Update 3. I found the source of the crash. Definitely a Dart issue, not Flutter. It's something to do with records, which makes sense given that it must have broken recently: extension MapUtils<K, V> on Map<K, V> {
Iterable<(K, V)> get records => entries.map((entry) => (entry.key, entry.value));
}
/* JSON structure for an "event":
{
"id": "123",
"name": "Event name",
"start": <Firestore Timestamp>,
"end": <Firestore Timestamp>,
"attendance": {
"123": { // Guest ID: Guest JSON object
"id": "123",
"name": "First, Last",
"email": "email@domain.com",
// ...
},
},
*/
Event.fromJson(Json json) :
id = json["id"],
name = json["name"]!,
start = (json["start"] as Timestamp).toDate(),
end = (json["end"] as Timestamp).toDate(),
attendance = {
// This does NOT work
for (final (String name, guestJson) in MapUtils<String, Map<String, dynamic>>(json["attendance"]).records)
// This DOES work
for (final (name, guestJson) in MapUtils<String, Map<String, dynamic>>(json["attendance"]).records)
name: Guest.fromJson(guestJson),
}; Notice that all I added to crash the compiler was |
dart2js
crashes on extension with records and type arguments
Thank you so much for the bug report and for isolating the root cause, it helps a lot! After I few iterations, it appears that the core issue here is with late-lowering on field initializers, but that we can repro the same failure even without extension methods and without type arguments. Here is a smaller repro that illustrates it: Iterable<(Object?, dynamic)> get values => [('a', 1), ('b', 'two')];
class A {
Map field = {
for (var (Object? n, v) in values) n: v,
};
}
main() => A(); |
I looked into this a bit too and see that the Dart2JS LateLowering assumes that every time a late field is read it will be in the context of a Function body. Initializer bodies are an exception to this but we should be able to treat initializer bodies as a similar scoping level: |
A fix for this has been submitted in https://dart-review.googlesource.com/c/sdk/+/323020 |
Thanks @biggs0125 |
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 <sigmund@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
I was running
flutter build web --web-renderer html
. I would post on Flutter's issues, but the error messages say it's an error with the compiler and to post here.Warnings during compilation
Compiler crash
Flutter Doctor
I am on Windows 11 build 22621.2134. The crash occurred on Flutter stable, beta, and master, up to Dart version
3.2.0-97.0.dev
.I'm not sure how much of the code I can share so I will try to get an MVP
Update 1: Creating a new project with the same exact
pubspec.yaml
ANDpubspec.lock
does not crash. I am runningflutter clean
before compiling and still getting the error, despite using the same version of Flutter/Dart on both projectsUpdate 2. Upgrading to the latest versions of all my packages did not help. Copying all the code under
lib
to the new project broke the new project as well.The text was updated successfully, but these errors were encountered: