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

[compiler is broken] dart2js failed when using object pattern that checks for == null, != null and _ wildcard #53518

Closed
hambergerpls opened this issue Sep 13, 2023 · 5 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js

Comments

@hambergerpls
Copy link

hambergerpls commented Sep 13, 2023

- Dart 3.1.1 (stable) (Tue Sep 5 12:20:14 2023 +0000) on "linux_x64"
- on linux / Linux 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023
- locale is en_US.UTF-8
flutter build web --release

Target dart2js failed: ProcessException: Process exited abnormally:
.dart_tool/flutter_build/87e9c14443d6c4520b47d6deb58aa331/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.1), and

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

The compiler crashed: Crash when compiling:
Bad state: No element

#0      List.last (dart:core-patch/growable_array.dart:348:5)
#1      LateLowering._addToCurrentScope (package:compiler/src/kernel/transformations/late_lowering.dart:212:28)
#2      LateLowering._initializedVariableCell (package:compiler/src/kernel/transformations/late_lowering.dart:262:12)
#3      LateLowering._variableCell (package:compiler/src/kernel/transformations/late_lowering.dart:221:11)
#4      LateLowering.transformVariableDeclaration (package:compiler/src/kernel/transformations/late_lowering.dart:275:12)
#5      _Lowering.visitVariableDeclaration (package:compiler/src/kernel/transformations/lowering.dart:73:26)
#6      VariableDeclaration.accept (package:kernel/ast.dart:10709:43)
#7      Transformer.transform (package:kernel/visitor.dart:1774:17)
#8      Transformer.transformList (package:kernel/visitor.dart:1791:18)
#9      Block.transformChildren (package:kernel/ast.dart:9185:7)
#10     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#11     TreeVisitor.defaultStatement (package:kernel/visitor.dart:415:41)
#12     TreeVisitor.visitBlock (package:kernel/visitor.dart:420:31)
#13     Block.accept (package:kernel/ast.dart:9173:43)
#14     Transformer.transform (package:kernel/visitor.dart:1774:17)
#15     BlockExpression.transformChildren (package:kernel/ast.dart:8788:14)
#16     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#17     TreeVisitor.defaultExpression (package:kernel/visitor.dart:223:43)
#18     TreeVisitor.visitBlockExpression (package:kernel/visitor.dart:350:51)
#19     BlockExpression.accept (package:kernel/ast.dart:8774:44)
#20     Transformer.transform (package:kernel/visitor.dart:1774:17)
#21     Transformer.transformList (package:kernel/visitor.dart:1791:18)
#22     Arguments.transformChildren (package:kernel/ast.dart:5425:7)
#23     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#24     TreeVisitor.visitArguments (package:kernel/visitor.dart:510:39)
#25     Arguments.accept (package:kernel/ast.dart:5410:38)
#26     Transformer.transform (package:kernel/visitor.dart:1774:17)
#27     SuperInitializer.transformChildren (package:kernel/ast.dart:3556:19)
#28     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#29     TreeVisitor.defaultInitializer (package:kernel/visitor.dart:486:45)
#30     TreeVisitor.visitSuperInitializer (package:kernel/visitor.dart:493:53)
#31     SuperInitializer.accept (package:kernel/ast.dart:3542:45)
#32     Transformer.transform (package:kernel/visitor.dart:1774:17)
#33     Transformer.transformList (package:kernel/visitor.dart:1791:18)
#34     Constructor.transformChildren (package:kernel/ast.dart:2768:7)
#35     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#36     TreeVisitor.defaultMember (package:kernel/visitor.dart:471:35)
#37     _Lowering.defaultMember (package:compiler/src/kernel/transformations/lowering.dart:44:18)
#38     TreeVisitor.visitConstructor (package:kernel/visitor.dart:473:43)
#39     Constructor.accept (package:kernel/ast.dart:2747:40)
#40     Transformer.transform (package:kernel/visitor.dart:1774:17)
#41     Transformer.transformList (package:kernel/visitor.dart:1791:18)
#42     Class.transformChildren (package:kernel/ast.dart:1475:7)
#43     Transformer.defaultTreeNode (package:kernel/visitor.dart:1808:10)
#44     TreeVisitor.visitClass (package:kernel/visitor.dart:480:31)
#45     Class.accept (package:kernel/ast.dart:1422:38)
#46     Transformer.transform (package:kernel/visitor.dart:1774:17)
#47     Transformer.transformList (package:kernel/visitor.dart:1791:18)
#48     Library.transformChildren (package:kernel/ast.dart:601:7)
#49     _Lowering.visitLibrary (package:compiler/src/kernel/transformations/lowering.dart:49:10)
#50     List.forEach (dart:core-patch/growable_array.dart:416:8)
#51     transformLibraries (package:compiler/src/kernel/transformations/lowering.dart:22:13)
#52     Dart2jsTarget.performModularTransformationsOnLibraries (package:compiler/src/kernel/dart2js_target.dart:179:14)
#53     KernelTarget.runBuildTransformations (package:front_end/src/fasta/kernel/kernel_target.dart:1571:19)
#54     KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:637:7)
<asynchronous suspension>
#55     withCrashReporting (package:front_end/src/fasta/crash.dart:133:12)
<asynchronous suspension>
#56     KernelTarget.buildComponent (package:front_end/src/fasta/kernel/kernel_target.dart:588:12)
<asynchronous suspension>
#57     _buildInternal (package:front_end/src/kernel_generator_impl.dart:210:19)
<asynchronous suspension>
#58     withCrashReporting (package:front_end/src/fasta/crash.dart:133:12)
<asynchronous suspension>
#59     compile.<anonymous closure> (package:front_end/src/api_unstable/dart2js.dart:198:37)
<asynchronous suspension>
#60     compile (package:front_end/src/api_unstable/dart2js.dart:196:36)
<asynchronous suspension>
#61     _loadFromSource (package:compiler/src/phase/load_kernel.dart:304:29)
<asynchronous suspension>
#62     run (package:compiler/src/phase/load_kernel.dart:417:36)
<asynchronous suspension>
#63     Compiler.loadKernel (package:compiler/src/compiler.dart:388:9)
<asynchronous suspension>
#64     Compiler.produceKernel (package:compiler/src/compiler.dart:395:36)
<asynchronous suspension>
#65     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:711:20)
<asynchronous suspension>
#66     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:311:7)
<asynchronous suspension>
#67     Compiler.runInternal (package:compiler/src/compiler.dart:310:5)
<asynchronous suspension>
#68     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:231:11)
<asynchronous suspension>
#69     main (package:compiler/src/dart2js.dart:1241:3)
<asynchronous suspension>
  Command: /home/danial/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/danial/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/home/danial/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/b8d35810e91ab8fc39ba5e7a41bff6f697e8e3a8/ --native-null-assertions --no-source-maps -o
  /home/danial/moi-systems/test_project/.dart_tool/flutter_build/87e9c14443d6c4520b47d6deb58aa331/app.dill --packages=.dart_tool/package_config.json --cfe-only
  /home/danial/moi-systems/test_project/.dart_tool/flutter_build/87e9c14443d6c4520b47d6deb58aa331/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...                              8.4s
Exception: Failed to compile application for the Web.

The following code crashes when trying to compile with flutter build web but works when running flutter run -d web-server

class Foo<T> {
  Foo(this.value);
  T? value;
}

class Bar extends Foo {
  Bar(Baz baz)
      : super(switch (baz) {
          Baz(someString: == null) => 'someString is empty',
          Baz(someString: != null) => 'someString is something',
          _ => 'someString is something else',
        });
}

class Baz {
  Baz();
  String? someString;
}

dart2js can compile when the switch statement contains either == null or != null.

// can compile
class Bar extends Foo {
  Bar(Baz baz)
      : super(switch (baz) {
          Baz(someString: == null) => 'someString is empty',
          _ => 'someString is something else',
        });
}

// can compile
class Bar extends Foo {
  Bar(Baz baz)
      : super(switch (baz) {
          Baz(someString: != null) => 'someString is something',
          _ => 'someString is empty',
        });
}
@sigmundch sigmundch added web-dart2js area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P1 A high priority bug; for example, a single project is unusable or has many test failures labels Sep 13, 2023
@sigmundch
Copy link
Member

Thanks so much for the error report and the detailed repro instructions.

We recently saw an issue with using pattern destructuring within initializers (see #53358), so I wonder if this and that issue are caused by the same bug. The fix for that other issue was approved to be cherry-picked (see #53449) and will be part of the next stable release (3.1.2).

@sigmundch
Copy link
Member

Just did a quick check in the master channel and the crash is still there, so this doesn't appear to be the same issue.

@sigmundch
Copy link
Member

My mistake - I checked using dartpad's notion of the master channel, but that's behind the current tip-of-tree. After checking locally I can confirm that it was indeed fixed by the same fix as the other issue. That is, using Dart 3.1.1 I can reproduce the crash, but downloading and running Dart 3.1.2 the crash goes away 🎉

It seems 3.1.2 was just released, so please give it a try and let us know if it doesn't work on your end. Thanks again!

@parlough
Copy link
Member

parlough commented Sep 13, 2023

As a note, Flutter 3.13.4 (or later) should have the fix as well.

dartpad's notion of the master channet, but that's behind the current tip-of-tree

Sorry about that! Working on getting it updated - dart-lang/dart-pad#2651

@hambergerpls
Copy link
Author

hambergerpls commented Sep 14, 2023

Good to hear! Thank you!

UPDATE: Can confirm that it works now 🎉

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. P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants