Skip to content

CFE crashes on a name conflict between a generative and a factory constructor #46745

@chloestefantsova

Description

@chloestefantsova

The following example makes the CFE crash:

class A {
  A._();
  factory A.foo() => A._();
  A.foo();
}

Here's the stack trace:

$ ./fasta compile --dump-ir -o /dev/null /tmp/asdf.dart
/tmp/asdf.dart:4:3: Error: 'A.foo' is already declared in this scope.
  A.foo();
  ^^^^^
/tmp/asdf.dart:3:11: Context: Previous declaration of 'A.foo'.
  factory A.foo() => A._();
          ^^^^^
Unhandled exception:
Crash when compiling null,
at character offset null:
type 'SourceFactoryBuilder' is not a subtype of type 'ConstructorBuilder' in type cast
#0      KernelTarget.finishConstructors.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:1057:34)
#1      ClassBuilderImpl.forEachDeclaredConstructor.callbackFilteringFieldBuilders (package:front_end/src/fasta/builder/class_builder.dart:465:17)
#2      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:400:8)
#3      ConstructorScope.forEach (package:front_end/src/fasta/scope.dart:593:11)
#4      ClassBuilderImpl.forEachDeclaredConstructor (package:front_end/src/fasta/builder/class_builder.dart:473:18)
#5      KernelTarget.finishConstructors (package:front_end/src/fasta/kernel/kernel_target.dart:1048:13)
#6      KernelTarget.finishAllConstructors (package:front_end/src/fasta/kernel/kernel_target.dart:898:9)
#7      KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:373:7)
<asynchronous suspension>
#8      withCrashReporting (package:front_end/src/fasta/crash.dart:121:12)
<asynchronous suspension>
#9      CompileTask.compile (file://(...)/sdk/pkg/front_end/tool/_fasta/entry_points.dart:368:9)
<asynchronous suspension>
#10     compile.<anonymous closure>.<anonymous closure> (file://(...)/sdk/pkg/front_end/tool/_fasta/entry_points.dart:247:14)
<asynchronous suspension>
#11     compile.<anonymous closure> (file://(...)/sdk/pkg/front_end/tool/_fasta/entry_points.dart:240:12)
<asynchronous suspension>
#12     runProtectedFromAbort (file://(...)/sdk/pkg/front_end/tool/_fasta/command_line.dart:515:12)
<asynchronous suspension>
#13     compile (file://(...)/sdk/pkg/front_end/tool/_fasta/entry_points.dart:239:10)
<asynchronous suspension>
#14     compileEntryPoint (file://(...)/sdk/pkg/front_end/tool/_fasta/entry_points.dart:75:5)
<asynchronous suspension>

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions