Open xvrh opened 1 month ago
Summary: The dart2js
compiler crashes during compilation of the chrome_extension
package due to a type mismatch error. The compiler attempts to cast an InterfaceType
to a FunctionType
, which is invalid, resulting in a crash.
It looks like there's a bug in JsInteropChecks.visitConstructor
where we're not recursing into the constructor's children to see if there are any errors.
Minimal repro:
import 'dart:js_interop';
class A {
A() {
Function f = (int x) => x;
x.toJS; // <-- This should get caught by a check before the transform.
}
}
Since the check is missing the error, the compiler continues to the transform which assumes everything is well-formed and eventually throws on the cast shown in the exception.
I'll put together a fix but in the meantime if you can find which .toJS
call is failing, then you will likely see that the static type of the function is Function
and not a more specific type like void Function()
. .toJS
only works when the static type is more specific (this is normally caught by the checker).
Nice repro isolation! Given the low risk and crash visibility, this may be a good candidate for filing a cherry-pick request.
Since Dart 3.5, we hit a compiler crash in the
chrome_extension
package (which use dart:js_interop internally).Full error message:
Target dart2js failed: ProcessException: Process exited abnormally with exit code 253:
``` Target dart2js failed: ProcessException: Process exited abnormally with exit code 253: .dart_tool/flutter_build/b7629c0c1f24a1cdb3a354a01092bc2f/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.5.0), 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: type 'InterfaceType' is not a subtype of type 'FunctionType' in type cast #0 JsUtilOptimizer._lowerFunctionToJS (package:_js_interop_checks/src/transformations/js_util_optimizer.dart:698:52) #1 JsUtilOptimizer.visitStaticInvocation (package:_js_interop_checks/src/transformations/js_util_optimizer.dart:502:20) #2 StaticInvocation.accept (package:kernel/ast.dart:6582:44) #3 Transformer.transform (package:kernel/visitor.dart:1771:17) #4 InstanceSet.transformChildren (package:kernel/ast.dart:4853:15) #5 Transformer.defaultTreeNode (package:kernel/visitor.dart:1805:10) #6 TreeVisitorDefault.defaultExpression (package:kernel/visitor.dart:618:43) #7 ExpressionVisitorDefaultMixin.visitInstanceSet (package:kernel/visitor.dart:109:43) #8 InstanceSet.accept (package:kernel/ast.dart:4835:44) #9 Transformer.transform (package:kernel/visitor.dart:1771:17) #10 ExpressionStatement.transformChildren (package:kernel/ast.dart:9141:20) #11 Transformer.defaultTreeNode (package:kernel/visitor.dart:1805:10) #12 TreeVisitorDefault.defaultStatement (package:kernel/visitor.dart:622:41) #13 StatementVisitorDefaultMixin.visitExpressionStatement (package:kernel/visitor.dart:343:7) #14 ExpressionStatement.accept (package:kernel/ast.dart:9128:43) #15 Transformer.transform (package:kernel/visitor.dart:1771:17) #16 Transformer.transformList (package:kernel/visitor.dart:1788:18) #17 Block.transformChildren (package:kernel/ast.dart:9193:7) #18 Transformer.defaultTreeNode (package:kernel/visitor.dart:1805:10) #19 TreeVisitorDefault.defaultStatement (package:kernel/visitor.dart:622:41) #20 StatementVisitorDefaultMixin.visitBlock (package:kernel/visitor.dart:345:31) #21 Block.accept (package:kernel/ast.dart:9181:43) #22 Transformer.transform (package:kernel/visitor.dart:1771:17) #23 FunctionNode.transformChildren (package:kernel/ast.dart:3905:16) #24 Transformer.defaultTreeNode (package:kernel/visitor.dart:1805:10) #25 TreeVisitorDefaultMixin.visitFunctionNode (package:kernel/visitor.dart:577:45) #26 FunctionNode.accept (package:kernel/ast.dart:3872:38) #27 Transformer.transform (package:kernel/visitor.dart:1771:17) #28 Constructor.transformChildren (package:kernel/ast.dart:2693:18) #29 JsUtilOptimizer.defaultMember (package:_js_interop_checks/src/transformations/js_util_optimizer.dart:143:10) #30 MemberVisitorDefaultMixin.visitConstructor (package:kernel/visitor.dart:409:43) #31 Constructor.accept (package:kernel/ast.dart:2671:40) #32 Transformer.transform (package:kernel/visitor.dart:1771:17) #33 Transformer.transformList (package:kernel/visitor.dart:1788:18) #34 Class.transformChildren (package:kernel/ast.dart:1524:7) #35 Transformer.defaultTreeNode (package:kernel/visitor.dart:1805:10) #36 TreeVisitorDefaultMixin.visitClass (package:kernel/visitor.dart:556:31) #37 Class.accept (package:kernel/ast.dart:1471:38) #38 Transformer.transform (package:kernel/visitor.dart:1771:17) #39 Transformer.transformList (package:kernel/visitor.dart:1788:18) #40 Library.transformChildren (package:kernel/ast.dart:609:7) #41 JsUtilOptimizer.visitLibrary (package:_js_interop_checks/src/transformations/js_util_optimizer.dart:135:10) #42 Dart2jsTarget.performModularTransformationsOnLibraries (package:compiler/src/kernel/dart2js_target.dart:169:25) #43 KernelTarget.runBuildTransformations (package:front_end/src/kernel/kernel_target.dart:1724:19) #44 KernelTarget.buildComponent.Reproduction:
dart pub get
dart compile js example/chrome_alarms.dart