Skip to content
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 crash (go_router problem?): Operand of null-aware operation '!' has type 'String' which excludes null #53291

Closed
Alexqwesa opened this issue Aug 21, 2023 · 11 comments
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@Alexqwesa
Copy link

Alexqwesa commented Aug 21, 2023

What didn't work:
flutter build web
Happens both times: with local build, and in github action (https://github.com/Alexqwesa/ais3uson_app/actions/runs/5918034312/job/16046960775)

What works:

flutter run -d Chrome
flutter run -d linux
flutter build appbundle
flutter build apk
flutter build linux

Output of flutter build web:


Target dart2js failed: ProcessException: Process exited abnormally:
../../.pub-cache/hosted/pub.dev/go_router-10.0.0/lib/src/information_provider.dart:125:34:
Warning: Operand of null-aware operation '!' has type 'String' which excludes null.
      location: routeInformation.location!,
                                 ^
../../.pub-cache/hosted/pub.dev/go_router-10.0.0/lib/src/parser.dart:87:50:
Warning: Operand of null-aware operation '!' has type 'String' which excludes null.
        configuration.findMatch(routeInformation.location!, extra: state.extra);
                                                 ^
file:///home/alex/AndroidStudioProjects/ais3uson_app/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/main.dart:
Internal Error: The compiler crashed when compiling this element.

The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

* the name and version of your operating system,

* the Dart SDK build number (3.1.0), and

* the entire message you see here (including the full stack trace
  below as well as the source location above).

The compiler crashed: Invalid argument(s): Type parameter TypeParameter(T) is not indexed
#0      TypeParameterIndexer.[] (package:kernel/binary/ast_to_binary.dart:3371:8)
#1      BinaryPrinter.visitTypeParameterType (package:kernel/binary/ast_to_binary.dart:2528:38)
#2      TypeParameterType.accept (package:kernel/ast.dart:12528:42)
#3      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#4      BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:349:7)
#5      BinaryPrinter.visitInterfaceType (package:kernel/binary/ast_to_binary.dart:2435:7)
#6      InterfaceType.accept (package:kernel/ast.dart:11385:42)
#7      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#8      BinaryPrinter.visitAsExpression (package:kernel/binary/ast_to_binary.dart:1960:5)
#9      AsExpression.accept (package:kernel/ast.dart:7636:44)
#10     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#11     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:531:7)
#12     BinaryPrinter.visitReturnStatement (package:kernel/binary/ast_to_binary.dart:2315:5)
#13     ReturnStatement.accept (package:kernel/ast.dart:10127:43)
#14     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#15     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:531:7)
#16     BinaryPrinter.visitFunctionNode (package:kernel/binary/ast_to_binary.dart:1529:5)
#17     FunctionNode.accept (package:kernel/ast.dart:3908:38)
#18     BinaryPrinter.writeFunctionNode (package:kernel/binary/ast_to_binary.dart:446:10)
#19     BinaryPrinter.visitProcedure (package:kernel/binary/ast_to_binary.dart:1357:5)
#20     Procedure.accept (package:kernel/ast.dart:3311:40)
#21     BinaryPrinter.writeProcedureNode (package:kernel/binary/ast_to_binary.dart:467:10)
#22     BinaryPrinter.writeProcedureNodeList (package:kernel/binary/ast_to_binary.dart:358:7)
#23     BinaryPrinter.visitClass (package:kernel/binary/ast_to_binary.dart:1260:5)
#24     Class.accept (package:kernel/ast.dart:1422:38)
#25     BinaryPrinter.writeClassNode (package:kernel/binary/ast_to_binary.dart:481:10)
#26     BinaryPrinter.writeClassNodeList (package:kernel/binary/ast_to_binary.dart:376:7)
#27     BinaryPrinter.visitLibrary (package:kernel/binary/ast_to_binary.dart:1096:5)
#28     Library.accept (package:kernel/ast.dart:577:38)
#29     BinaryPrinter.writeLibraryNode (package:kernel/binary/ast_to_binary.dart:460:10)
#30     BinaryPrinter.writeLibraries (package:kernel/binary/ast_to_binary.dart:766:9)
#31     BinaryPrinter.writeComponentFile.<anonymous closure> (package:kernel/binary/ast_to_binary.dart:605:7)
#32     Timeline.timeSync (dart:developer/timeline.dart:171:22)
#33     BinaryPrinter.writeComponentFile (package:kernel/binary/ast_to_binary.dart:586:14)
#34     SerializationTask.serializeComponent.<anonymous closure> (package:compiler/src/serialization/task.dart:77:15)
#35     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#36     SerializationTask.serializeComponent (package:compiler/src/serialization/task.dart:67:5)
#37     Compiler.produceKernel (package:compiler/src/compiler.dart:422:29)
<asynchronous suspension>
#38     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:711:20)
<asynchronous suspension>
#39     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:311:7)
<asynchronous suspension>
#40     Compiler.runInternal (package:compiler/src/compiler.dart:310:5)
<asynchronous suspension>
#41     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:231:11)
<asynchronous suspension>
#42     main (package:compiler/src/dart2js.dart:1241:3)
<asynchronous suspension>
  Command: /home/alex/Android/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/alex/Android/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/home/alex/Android/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true -DFLUTTER_WEB_AUTO_DETECT=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/1ac611c64eadbd93c5f5aba5494b8fc3b35ee952/ --native-null-assertions --no-source-maps -o
  /home/alex/AndroidStudioProjects/ais3uson_app/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/app.dill --packages=.dart_tool/package_config.json --cfe-only
  /home/alex/AndroidStudioProjects/ais3uson_app/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:125:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:278:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:189:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:89:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:198:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:285:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:115:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                             11.9s
Exception: Failed to compile application for the Web.

flutter doctor --verbose

[✓] Flutter (Channel stable, 3.13.0, on openSUSE Leap 15.5 5.14.21-150500.55.12-default, locale en_US.UTF-8)
    • Flutter version 3.13.0 on channel stable at /home/alex/Android/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision efbf63d9c6 (vor 5 Tagen), 2023-08-15 21:05:06 -0500
    • Engine revision 1ac611c64e
    • Dart version 3.1.0
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/alex/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /home/alex/Android/Sdk
    • Java binary at: /home/alex/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-1/223.8836.35.2231.10406996/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 15.0.7
    • cmake version 3.20.4
    • ninja version 1.10.0
    • pkg-config version 0.29.2

[✓] Android Studio (version 2022.3)
    • Android Studio at /home/alex/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-1/223.8836.35.2231.10406996
    • Flutter plugin version 74.0.3
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.75.1)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • openSUSE Leap 15.5 5.14.21-150500.55.12-default
    • Chrome (web)    • chrome • web-javascript • Google Chrome 116.0.5845.96

[✓] Network resources
    • All expected network resources are available.

• No issues found!
Process finished with exit code 0```
@mit-mit mit-mit added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Aug 21, 2023
@Alexqwesa
Copy link
Author

Alexqwesa commented Aug 21, 2023

After some trying I found, if you add into new flutter project:

dependencies:
  record: ^5.0.0-beta.2

then flutter build web will fail with this error:

Resolving dependencies... 
  collection 1.17.2 (1.18.0 available)
+ crypto 3.0.3
+ flutter_web_plugins 0.0.0 from sdk flutter
+ js 0.6.7
  material_color_utilities 0.5.0 (0.8.0 available)
+ plugin_platform_interface 2.1.5
+ record 5.0.0-beta.2
+ record_android 1.0.0-beta.2
+ record_darwin 1.0.0-beta.2+2
+ record_linux 0.6.0
+ record_platform_interface 1.0.1
+ record_web 1.0.0-beta.2+2
+ record_windows 1.0.0-beta.2
  stack_trace 1.11.0 (1.11.1 available)
  stream_channel 2.1.1 (2.1.2 available)
  test_api 0.6.0 (0.6.1 available)
+ typed_data 1.3.2
+ uuid 3.0.7
Changed 13 dependencies!




Target dart2js failed: ProcessException: Process exited abnormally:
file:///home/alex/AndroidStudioProjects/dart2js_crash_for_bug_report/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/main.dart:
Internal Error: The compiler crashed when compiling this element.

The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

* the name and version of your operating system,

* the Dart SDK build number (3.1.0), and

* the entire message you see here (including the full stack trace
  below as well as the source location above).

The compiler crashed: Invalid argument(s): Type parameter TypeParameter(T) is not indexed
#0      TypeParameterIndexer.[] (package:kernel/binary/ast_to_binary.dart:3371:8)
#1      BinaryPrinter.visitTypeParameterType (package:kernel/binary/ast_to_binary.dart:2528:38)
#2      TypeParameterType.accept (package:kernel/ast.dart:12528:42)
#3      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#4      BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:349:7)
#5      BinaryPrinter.visitInterfaceType (package:kernel/binary/ast_to_binary.dart:2435:7)
#6      InterfaceType.accept (package:kernel/ast.dart:11385:42)
#7      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#8      BinaryPrinter.visitAsExpression (package:kernel/binary/ast_to_binary.dart:1960:5)
#9      AsExpression.accept (package:kernel/ast.dart:7636:44)
#10     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#11     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:531:7)
#12     BinaryPrinter.visitReturnStatement (package:kernel/binary/ast_to_binary.dart:2315:5)
#13     ReturnStatement.accept (package:kernel/ast.dart:10127:43)
#14     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:439:10)
#15     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:531:7)
#16     BinaryPrinter.visitFunctionNode (package:kernel/binary/ast_to_binary.dart:1529:5)
#17     FunctionNode.accept (package:kernel/ast.dart:3908:38)
#18     BinaryPrinter.writeFunctionNode (package:kernel/binary/ast_to_binary.dart:446:10)
#19     BinaryPrinter.visitProcedure (package:kernel/binary/ast_to_binary.dart:1357:5)
#20     Procedure.accept (package:kernel/ast.dart:3311:40)
#21     BinaryPrinter.writeProcedureNode (package:kernel/binary/ast_to_binary.dart:467:10)
#22     BinaryPrinter.writeProcedureNodeList (package:kernel/binary/ast_to_binary.dart:358:7)
#23     BinaryPrinter.visitClass (package:kernel/binary/ast_to_binary.dart:1260:5)
#24     Class.accept (package:kernel/ast.dart:1422:38)
#25     BinaryPrinter.writeClassNode (package:kernel/binary/ast_to_binary.dart:481:10)
#26     BinaryPrinter.writeClassNodeList (package:kernel/binary/ast_to_binary.dart:376:7)
#27     BinaryPrinter.visitLibrary (package:kernel/binary/ast_to_binary.dart:1096:5)
#28     Library.accept (package:kernel/ast.dart:577:38)
#29     BinaryPrinter.writeLibraryNode (package:kernel/binary/ast_to_binary.dart:460:10)
#30     BinaryPrinter.writeLibraries (package:kernel/binary/ast_to_binary.dart:766:9)
#31     BinaryPrinter.writeComponentFile.<anonymous closure> (package:kernel/binary/ast_to_binary.dart:605:7)
#32     Timeline.timeSync (dart:developer/timeline.dart:171:22)
#33     BinaryPrinter.writeComponentFile (package:kernel/binary/ast_to_binary.dart:586:14)
#34     SerializationTask.serializeComponent.<anonymous closure> (package:compiler/src/serialization/task.dart:77:15)
#35     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#36     SerializationTask.serializeComponent (package:compiler/src/serialization/task.dart:67:5)
#37     Compiler.produceKernel (package:compiler/src/compiler.dart:422:29)
<asynchronous suspension>
#38     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:711:20)
<asynchronous suspension>
#39     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:311:7)
<asynchronous suspension>
#40     Compiler.runInternal (package:compiler/src/compiler.dart:310:5)
<asynchronous suspension>
#41     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:231:11)
<asynchronous suspension>
#42     main (package:compiler/src/dart2js.dart:1241:3)
<asynchronous suspension>
  Command: /home/alex/Android/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/alex/Android/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/home/alex/Android/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true -DFLUTTER_WEB_AUTO_DETECT=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/1ac611c64eadbd93c5f5aba5494b8fc3b35ee952/ --native-null-assertions --no-source-maps -o
  /home/alex/AndroidStudioProjects/dart2js_crash_for_bug_report/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/app.dill --packages=.dart_tool/package_config.json --cfe-only
  /home/alex/AndroidStudioProjects/dart2js_crash_for_bug_report/.dart_tool/flutter_build/0a29fdf56dfc3214f350e0e2ab50d35c/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:125:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:278:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:189:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:853:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:525:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:791:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:620:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:89:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:198:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:285:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:115:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:90:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                              7.6s
Exception: Failed to compile application for the Web.

@sigmundch sigmundch added web-eval evaluation support on the web web-dart2js and removed web-eval evaluation support on the web labels Aug 21, 2023
@fishythefish
Copy link
Member

It looks like this error occurs when the CFE attempts to serialize the AST.

cc @johnniwinther

@fishythefish fishythefish added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Aug 21, 2023
@sigmundch
Copy link
Member

sigmundch commented Aug 24, 2023

Seems that the issue is coming up when trying to serialize the consturctor-tearoff of a static interop class that has a generic parameter.

In the code above it is caused by the JsIterator declaration: https://github.com/llfbandit/record/blob/master/record_web/lib/js/js_interop/core.dart#L125

Here is a standalone repro with no external dependencies using dart:js_interop instead of package:js:

import 'dart:js_interop';

@anonymous
@JS('Iterator')
@staticInterop
class JsIterator<T> {
  external factory JsIterator();
}

main() {}

Then running dart2js --cfe-only a.dart produces this crash:

The compiler crashed: Invalid argument(s): Type parameter TypeParameter(T) is not indexed
#0      TypeParameterIndexer.[] (package:kernel/binary/ast_to_binary.dart:3350:8)
#1      BinaryPrinter.visitTypeParameterType (package:kernel/binary/ast_to_binary.dart:2523:38)
#2      TypeParameterType.accept (package:kernel/ast.dart:12217:42)
#3      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:440:10)
#4      BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:349:7)
#5      BinaryPrinter.visitInterfaceType (package:kernel/binary/ast_to_binary.dart:2436:7)
#6      InterfaceType.accept (package:kernel/ast.dart:11195:42)
#7      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:440:10)
#8      BinaryPrinter.visitAsExpression (package:kernel/binary/ast_to_binary.dart:1961:5)
#9      AsExpression.accept (package:kernel/ast.dart:7459:44)
#10     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:440:10)
#11     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:532:7)
#12     BinaryPrinter.visitReturnStatement (package:kernel/binary/ast_to_binary.dart:2316:5)
#13     ReturnStatement.accept (package:kernel/ast.dart:9950:43)
#14     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:440:10)
#15     BinaryPrinter.writeOptionalNode (package:kernel/binary/ast_to_binary.dart:532:7)
#16     BinaryPrinter.visitFunctionNode (package:kernel/binary/ast_to_binary.dart:1530:5)
#17     FunctionNode.accept (package:kernel/ast.dart:3721:38)
#18     BinaryPrinter.writeFunctionNode (package:kernel/binary/ast_to_binary.dart:447:10)
#19     BinaryPrinter.visitProcedure (package:kernel/binary/ast_to_binary.dart:1358:5)
#20     Procedure.accept (package:kernel/ast.dart:3124:40)
#21     BinaryPrinter.writeProcedureNode (package:kernel/binary/ast_to_binary.dart:468:10)
#22     BinaryPrinter.writeProcedureNodeList (package:kernel/binary/ast_to_binary.dart:358:7)
#23     BinaryPrinter.visitClass (package:kernel/binary/ast_to_binary.dart:1261:5)
#24     Class.accept (package:kernel/ast.dart:1426:38)
#25     BinaryPrinter.writeClassNode (package:kernel/binary/ast_to_binary.dart:482:10)
#26     BinaryPrinter.writeClassNodeList (package:kernel/binary/ast_to_binary.dart:376:7)
#27     BinaryPrinter.visitLibrary (package:kernel/binary/ast_to_binary.dart:1097:5)
#28     Library.accept (package:kernel/ast.dart:581:38)
#29     BinaryPrinter.writeLibraryNode (package:kernel/binary/ast_to_binary.dart:461:10)
#30     BinaryPrinter.writeLibraries (package:kernel/binary/ast_to_binary.dart:767:9)
#31     BinaryPrinter.writeComponentFile.<anonymous closure> (package:kernel/binary/ast_to_binary.dart:606:7)
#32     Timeline.timeSync (dart:developer/timeline.dart:173:22)
#33     BinaryPrinter.writeComponentFile (package:kernel/binary/ast_to_binary.dart:587:14)
#34     SerializationTask.serializeComponent.<anonymous closure> (package:compiler/src/serialization/task.dart:78:15)
#35     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#36     SerializationTask.serializeComponent (package:compiler/src/serialization/task.dart:68:5)
#37     Compiler.produceKernel (package:compiler/src/compiler.dart:422:29)
<asynchronous suspension>
#38     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:711:20)
<asynchronous suspension>
#39     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:311:7)
<asynchronous suspension>
#40     Compiler.runInternal (package:compiler/src/compiler.dart:310:5)
<asynchronous suspension>
#41     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:231:11)
<asynchronous suspension>
#42     compile.<anonymous closure> (package:compiler/compiler_api.dart:249:30)
<asynchronous suspension>
#43     compile.compilationDone (package:compiler/src/dart2js.dart:738:3)
<asynchronous suspension>
#44     main (package:compiler/src/dart2js.dart:1241:3)
<asynchronous suspension>

Removing the type parameter indeed circumvents this crash (note that being an external class, the type parameter has no purpose so it is safe to be removed and to keep it only in the static extension). That said, we should make the tool chain more robust to ensure it doesn't crash on cases like these.

@sigmundch
Copy link
Member

cc @srujzs

A few things to highlight:

  • using the tear-offs is disallowed by our interop checker, so those tearoffs are not going to be invoked.
  • removing @anonymous from the example, also elides this issue. I believe this is because non-anonymous external factory constructors are lowered to a non-external static constructor that invokes js_util.callConstructor, the anonymous ones remain a tearoff pointing to the external factory directly.
  • I haven't yet been able to repro using only fasta commands (e.g. using a fasta compile elides this crash for some reason).

@srujzs
Copy link
Contributor

srujzs commented Aug 24, 2023

using the tear-offs is disallowed by our interop checker, so those tearoffs are not going to be invoked.

Yes, but this only applies to @staticInterop classes and not other package:js classes.

@johnniwinther
Copy link
Member

I'll take a look.

@johnniwinther
Copy link
Member

The problem is in

newInvocation, node.target.function.returnType as InterfaceType)

The node.target.function.returnType is not the JavaScriptObject type as intended given the comment in
// Add a cast so that the result gets typed as `JavaScriptObject`.
but instead the return type of a constructor tearoff, which is generic and therefore needs to substituted wrt to type arguments of the invocation for it to be valid.

@sigmundch
Copy link
Member

Thank so much @johnniwinther for your help investigating here!

@sigmundch sigmundch added web-js-interop Issues that impact all js interop and removed web-dart2js area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Aug 30, 2023
@srujzs srujzs self-assigned this Aug 30, 2023
@srujzs
Copy link
Contributor

srujzs commented Aug 30, 2023

I think we want to rather erase that type in the cast, which we aren't doing now, which fixes this issue. The generic tear-off's return type will be erased, so it makes sense to align it there.

https://dart-review.googlesource.com/c/sdk/+/323505

@sigmundch
Copy link
Member

@srujzs - Given that the issue produces a crash that potentially multiple users have encountered, and that the fix is pretty contained and low risk, we should consider filing a cherry-pick for including it in the stable channel

@srujzs
Copy link
Contributor

srujzs commented Sep 11, 2023

Yeah, I think working around this issue is a bit of a pain per my comment on the related issue, so a cherry-pick makes sense. I'll go ahead and file one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

6 participants