Skip to content

[dart2js] List.unmodifiable fails to run on web #59790

@sunarya-thito

Description

@sunarya-thito

Steps to Reproduce

  1. Add this code
for (int i = 0; i < List.unmodifiable([]).length; i++) {}

for example

void main() {
  for (int i = 0; i < List.unmodifiable([]).length; i++) {}
  runApp(const MyApp());
}
  1. Run it with flutter web (on profile or release mode)
flutter run -d chrome --release

or you can also compile it with dart2js, which generate the js code below

    main() {
      var t1, i, result;
      result.$flags = 3;
      for (t1 = type$.dynamic, i = 0; result = A.List_List$from([], false, t1), i < result.length; ++i)
        ;
    }
  1. You will get this error
Uncaught Error: Error: Cannot set properties of undefined (setting '$flags')
    at main.dart:114:65
    at _wrapJsFunctionForAsync_closure.$protected (async_patch.dart:311:19)
    at _wrapJsFunctionForAsync_closure.call$2 (async_patch.dart:336:23)
    at _awaitOnObject_closure.call$1 (async_patch.dart:287:19)
    at _RootZone.runUnary$2$2 (zone.dart:1676:46)
    at _RootZone.runUnary$2 (zone.dart:1675:5)
    at _Future__propagateToListeners_handleValueCallback.call$0 (future_impl.dart:169:29)
    at Object._Future__propagateToListeners (future_impl.dart:931:13)
    at _Future._completeWithValue$1 (future_impl.dart:707:5)
    at _Future__asyncCompleteWithValue_closure.call$0 (future_impl.dart:777:7)

from

    main() {
      var t1, i, result;
      result.$flags = 3;
      for (t1 = type$.dynamic, i = 0; result = A.List_List$from([], false, t1), i < result.length; ++i)
        ;
    }

the result variable is not initialized with a value, but it tries to set its flag to 3

Dart Version

Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "windows_x64"

I understand that the code isn't good or anything, but this shouldn't happen, right? I don't know what else it might cause, it runs perfectly on debug mode and other platform

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dart2js-ssatype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions