Closed mono0926 closed 2 years ago
It is hard to guess where to start with this because the part that tells us where the error happened is not specific.
Target dart2js failed: Exception: .dart_tool/flutter_build/6c1142c37fb0b5a7878591c90dbc00fe/app.dill:
Internal Error: The compiler crashed when compiling this element.
The first step might be to make this message a little more helpful.
I re-run the command.
# with `-v` option
flutter build web --target lib/main.dart -v
And, also reproduced in 2.9.0-0.1.pre/2.16.0-80.1.beta.
@rakudrama I believe to get additional info we probably need to land some changes in the compiler first.
In particular,
Target dart2js failed: Exception: .dart_tool/flutter_build/6c1142c37fb0b5a7878591c90dbc00fe/app.dill:
Is likely due to how flutter tools are invoking dart2js. It's quite likely that they use the 2 step approach of first compiling to dill and then running the backend. I'm not sure if flutter tools provide a flag to bypass this mode (/cc @yjbanov ). Even if they do, I don't expect it to tell us more (other than report a different URI for the entrypoint of the application). I don't expect more info because the issue is coming up in a phase that is not recording which element was being processed when the error was encountered. We could however change the compiler to do so.
At a glance, it appears there is an invariant broken where we expect every closure model converted to the JS world to have a non-null scopeInfo
property, but in this case the scope info is null. Looking at the scope_visitor, the rules that ensure the scopeInfo is assigned are subtle and it's quite likely we are breaking this invariant.
After the above change, it is likely that the error will show up with a source location.
If the source location looks like foo.dart@12345+1
it means 12345 characters into source file foo.dart
.
Hopefully this will allow us identify the file/class/method where the problem occurs.
@rakudrama
Thanks, I'll try it when the Dart version included in the latest Flutter master version is 2.16.0-154.0.dev
or higher.
Current latest is Flutter 2.9.0-1.0.pre.256
(Dart 2.16.0-144.0.dev
).
@rakudrama
I've confirmed with Dart 2.16.0-159.0.dev
It says the error occurs here:
abstract class _Icon implements CategoryIcon {
const factory _Icon([String iconName]) = _$_Icon; // HERE!
factory _Icon.fromJson(Map<String, dynamic> json) = _$_Icon.fromJson;
String get iconName;
@JsonKey(ignore: true)
_$IconCopyWith<_Icon> get copyWith => throw _privateConstructorUsedError;
}
That is internal huge Flutter project, so I tried to create reproduciable simple project, but it was succeeded to build π€
I've got the same issue. After changing the type of parameters to named ones and regenerating the freezed files, everything was compiled
@DenisovAV
Thanks, that workaround also fixed my issue π
I keep this issue open since the problem is still unresolved.
We are still working on trying to reproduce this, but haven't quite managed to.
@DenisovAV - by chance do you have a small example we can use?
@mono0926 - on your example:
_Icon
is generated by freezed
. What does the original declaration of Icon/CategoryIcon look like? I tried to create a snippet that would generate code such as what you have, but I couldn't quite replicate it. Playing around with the patterns I saw in the generated code I was able to create a standalone repro:
abstract class A {
const A._();
const factory A([String field]) = B;
}
abstract class B extends A {
const B._() : super._();
const factory B([String field]) = C;
String get field;
}
class C extends B {
const C([this.field = '']) : super._();
final String field;
}
main() {
A.new;
}
This also crashes with the same error.
/cc @rakudrama
(edit: simplified the names of the classes in the repro)
Nice repro. The debug version of dart2js crashes earlier with an assertion failure.
Hi, I'm getting this error now, what should I do to fix this?
Thank you @sigmundch for being so thorough with this - Taking inspo from your comment, I removed all the .new
calls in my code and it fixed the bug. I second his repro.
@rakudrama - looking at the report from @Miiite in https://github.com/dart-lang/sdk/issues/48491, I noticed that the use of optional parameters was not relevant, then I noticed that the use of super
wasn't either. Here is a smaller repro:
abstract class A {
const factory A() = B;
}
abstract class B implements A {
const factory B() = C;
}
class C implements B {
const C();
}
main() {
A.new;
}
Any insights so far from the broken assertion?
Experiencing the same issue, unable to find a fix for this. The error seems to suggest what @sigmundch has reproed.
Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
lib/app/pages/signals/application/signal-actor-bloc/signal-actor-bloc.cg.freezed.dart:5940:17:
Internal Error: The compiler crashed when compiling this element.
const factory _ReportInaccurateSignalFailure(SignalsFailure failure) =
^
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 (2.17.0-165.0.dev), and
* the entire message you see here (including the full stack trace
below as well as the source location above).
The compiler crashed: NoSuchMethodError: The getter 'boxedVariables' was called on null.
Receiver: null
Tried calling: boxedVariables
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1 JsKernelToElementMap.makeRecordContainer (package:compiler/src/js_model/element_map_impl.dart:1770:14)
#2 ClosureDataBuilder.createClosureEntities.processModel (package:compiler/src/js_model/closure.dart:329:23)
#3 ClosureDataBuilder.createClosureEntities.<anonymous closure>.<anonymous closure>
(package:compiler/src/js_model/closure.dart:389:9)
#4 CompilerDiagnosticReporter.withCurrentElement (package:compiler/src/compiler.dart:1025:15)
#5 ClosureDataBuilder.createClosureEntities.<anonymous closure> (package:compiler/src/js_model/closure.dart:388:17)
#6 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:579:13)
#7 ClosureDataBuilder.createClosureEntities (package:compiler/src/js_model/closure.dart:387:19)
#8 JsClosedWorldBuilder.convertClosedWorld (package:compiler/src/js_model/js_world_builder.dart:161:41)
#9 JsBackendStrategy.createJClosedWorld (package:compiler/src/js_model/js_strategy.dart:174:52)
#10 Compiler.closeResolution (package:compiler/src/compiler.dart:610:25)
#11 Compiler.computeClosedWorld (package:compiler/src/compiler.dart:470:9)
#12 Compiler.compileFromKernel.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:572:17)
#13 CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#14 Compiler.compileFromKernel.<anonymous closure> (package:compiler/src/compiler.dart:571:44)
#15 CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#16 Compiler.compileFromKernel (package:compiler/src/compiler.dart:570:14)
#17 Compiler.runInternal (package:compiler/src/compiler.dart:372:17)
<asynchronous suspension>
#18 main (package:compiler/src/dart2js.dart:1392:3)
<asynchronous suspension>
[ +17 ms] Compiling lib/main.dart for the Web... (completed in 30.2s)
[ +1 ms] "flutter web" took 31,363ms.
[ +4 ms] Exception: Failed to compile application for the Web.
[ ]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 buildWeb (package:flutter_tools/src/web/compile.dart:81:5)
<asynchronous suspension>
#2 BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:112:5)
<asynchronous suspension>
#3 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1165:27)
<asynchronous suspension>
#4 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#5 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#6 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
<asynchronous suspension>
#7 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#8 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
<asynchronous suspension>
#9 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
<asynchronous suspension>
#10 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#11 main (package:flutter_tools/executable.dart:94:3)
<asynchronous suspension>
[ +90 ms] ensureAnalyticsSent: 88ms
[ +1 ms] Running shutdown hooks
[ ] Shutdown hooks complete
[ ] exiting with code 1
In the Kernel IR, uses of a redirecting constructor are replaced by uses of the target. This appears to happen for just one step of redirection.
For the small example above, the IR is as follows.
(I added B.new;
to main
)
B._#new#tearOff
calls C()
, a generative constructor.
A._#new#tearOff
calls B()
, a redirecting const factory constructor.
@johnniwinther It seems that the CFE should fully lower the feature or leave it in-place. Currently the K-model ignores redirecting construstors, so it seems that the intention was to fully lower. Are there impediments to full lowering, e.g. modularity concerns?
library from "file://47916.dart" as 479 {
abstract class A extends core::Object {
static final field dynamic _redirecting# = <dynamic>[#C1]/*isLegacy*/;
static factory β’() β 479::A
return 479::B::β’();
static method _#new#tearOff() β 479::A
return 479::B::β’();
}
abstract class B extends core::Object implements 479::A {
static final field dynamic _redirecting# = <dynamic>[#C2]/*isLegacy*/;
static factory β’() β 479::B
return new 479::C::β’();
static method _#new#tearOff() β 479::B
return new 479::C::β’();
}
class C extends core::Object implements 479::B /*hasConstConstructor*/ {
const constructor β’() β 479::C
: super core::Object::β’()
;
static method _#new#tearOff() β 479::C
return new 479::C::β’();
}
static method main() β dynamic {
#C3;
#C4;
}
}
...
constants {
#C1 = constructor-tearoff 479::A::β’
#C2 = constructor-tearoff 479::B::β’
#C3 = static-tearoff 479::A::_#new#tearOff
#C4 = static-tearoff 479::B::_#new#tearOff
...
}
It is an error in the lowering. A
should have invoked its effective target, C
, and not it's immediate target B
.
I'll work on a fix.
Hi @johnniwinther, Will this be included as hotfix? As I checked the latest version of dart in flutter master channel is 2.17.0-182.0.dev. But this commit is included in versions starting from 2.17.0-188.0.dev.
Is there a way to change dart version in flutter sdk?
Hi, I have this problem with almost every flutter project I am creating.
@timfong888 - thanks for letting us know.
Note that the fix landed a few months ago and was subsequently cherry-picked into Dart and Flutter release channels, so all fixes have been available since Flutter 2.10.4. If you are on the latest version of Flutter and are seeing a similar error, it is quite possible it is caused by something else. If that's the case, could you file a new bug with more details so we can investigate?
@sigmundch thanks for getting back. I am using CodeMagic to run the builds (the errors were the same as I was getting locally, but I thought a fresh VM each build would eliminate some environment issues).
Run
flutter build web --target lib/main.dart
on my internal project, and the compiler crashes. Sorry, I couldn't make a reproducible public code.Log:
This tracker is for issues related to: