dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.56k forks source link

dart2js crashes when using `covariant` incorrectly in a method defined in another method body #48372

Open natebosch opened 2 years ago

natebosch commented 2 years ago

The following code has a static error. Attempting to compiled with dart compile js causes a crash instead of an error pointing to the incorrect use of covariant.

void main() {
  void stuff(covariant String s) {}
}
Info: Compiling with sound null safety
web/main.dart:1:6:
Internal Error: The compiler crashed when compiling this element.
void main() {
     ^
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-85.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: type 'FunctionDeclarationImpl' is not a subtype of type 'Procedure' in type cast
#0      KernelToElementMapImpl.getFunctionType.getParameterType (package:compiler/src/kernel/element_map_impl.dart:522:24)
#1      KernelToElementMapImpl.getFunctionType (package:compiler/src/kernel/element_map_impl.dart:531:28)
#2      KernelToElementMapImpl.getLocalFunction (package:compiler/src/kernel/element_map_impl.dart:1506:36)
#3      KernelImpactRegistryMixin.registerLocalFunction (package:compiler/src/kernel/kernel_impact.dart:713:33)
#4      ImpactBuilderBase.handleFunctionDeclaration (package:compiler/src/ir/impact.dart:340:5)
#5      StaticTypeVisitor.visitFunctionDeclaration (package:compiler/src/ir/static_type.dart:1705:5)
#6      FunctionDeclaration.accept (package:kernel/ast.dart:10523:43)
#7      StaticTypeBase.visitNode (package:compiler/src/ir/static_type_base.dart:78:18)
#8      StaticTypeVisitor.visitBlock (package:compiler/src/ir/static_type.dart:1311:22)
#9      Block.accept (package:kernel/ast.dart:8906:43)
#10     StaticTypeBase.visitNode (package:compiler/src/ir/static_type_base.dart:78:18)
#11     StaticTypeVisitor.visitProcedure (package:compiler/src/ir/static_type.dart:1736:5)
#12     Procedure.accept (package:kernel/ast.dart:3176:40)
#13     KernelToElementMapImpl.computeWorldImpact (package:compiler/src/kernel/element_map_impl.dart:1436:12)
#14     KernelWorkItem.run.<anonymous closure>.<anonymous closure> (package:compiler/src/kernel/kernel_strategy.dart:404:47)
#15     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#16     KernelWorkItem.run.<anonymous closure> (package:compiler/src/kernel/kernel_strategy.dart:403:28)
#17     CompilerTask.measure (package:compiler/src/common/tasks.dart:66:51)
#18     KernelWorkItem.run (package:compiler/src/kernel/kernel_strategy.dart:378:26)
#19     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:609:70)
#20     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#21     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:609:32)
#22     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#23     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:607:28)
#24     CompilerDiagnosticReporter.withCurrentElement (package:compiler/src/compiler.dart:898:15)
#25     Compiler.emptyQueue.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:605:18)
#26     ResolutionEnqueuer._forEach (package:compiler/src/enqueue.dart:441:12)
#27     ResolutionEnqueuer.forEach (package:compiler/src/enqueue.dart:457:5)
#28     Compiler.emptyQueue.<anonymous closure> (package:compiler/src/compiler.dart:601:16)
#29     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#30     Compiler.emptyQueue (package:compiler/src/compiler.dart:600:14)
#31     Compiler.processQueue.<anonymous closure> (package:compiler/src/compiler.dart:626:7)
#32     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#33     Compiler.processQueue (package:compiler/src/compiler.dart:619:14)
#34     Compiler.computeClosedWorld (package:compiler/src/compiler.dart:448:5)
#35     Compiler.compileFromKernel.<anonymous closure>.<anonymous closure> (package:compiler/src/compiler.dart:561:17)
#36     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#37     Compiler.compileFromKernel.<anonymous closure> (package:compiler/src/compiler.dart:560:44)
#38     CompilerTask.measureSubtask (package:compiler/src/common/tasks.dart:181:35)
#39     Compiler.compileFromKernel (package:compiler/src/compiler.dart:559:14)
#40     Compiler.runInternal (package:compiler/src/compiler.dart:363:17)
<asynchronous suspension>
#41     CompilerImpl.run.<anonymous closure> (package:compiler/src/apiimpl.dart:60:22)
<asynchronous suspension>
#42     main (package:compiler/src/dart2js.dart:1392:3)
<asynchronous suspension>
sigmundch commented 2 years ago

We can prevent this crash in dart2js, but this should have been detected earlier by the CFE. That program produces no errors in the CFE today (even when running on the commandline VM), but produces an error from analyzer.