[cfe] Require a non-null name for mixin supertypes

The function types are given an empty name in that case. Those types
are further discarded and can have any intermediary name.

Part of https://github.com/dart-lang/sdk/issues/48919

Change-Id: I57d223ee7914d0227baa3a4ef5733bb8055fa2c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244240
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
index 77c6eaa..53fa58e 100644
--- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
@@ -2149,7 +2149,18 @@
       /// 1. `_Named&S&M1`
       /// 2. `_Named&S&M1&M2`
       /// 3. `Named`.
-      String runningName = extractName(supertype.name);
+      Object nameSourceForExtraction;
+      if (supertype.name == null) {
+        assert(supertype is FunctionTypeBuilder);
+
+        // Function types don't have names, and we can supply any string that
+        // doesn't have to be unique. The actual supertype of the mixin will
+        // not be built in that case.
+        nameSourceForExtraction = "";
+      } else {
+        nameSourceForExtraction = supertype.name!;
+      }
+      String runningName = extractName(nameSourceForExtraction);
 
       /// True when we're building a named mixin application. Notice that for
       /// the `Named` example above, this is only true on the last
@@ -5245,7 +5256,9 @@
       declaration.charOffset, declaration.fileUri);
 }
 
-String extractName(name) => name is QualifiedName ? name.name : name;
+String extractName(Object name) {
+  return name is QualifiedName ? name.name : name as String;
+}
 
 class PostponedProblem {
   final Message message;
diff --git a/pkg/front_end/testcases/general/issue48919.dart b/pkg/front_end/testcases/general/issue48919.dart
new file mode 100644
index 0000000..9bec7cc
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart
@@ -0,0 +1,8 @@
+// Copyright (c) 2022, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+mixin M {}
+class A = void Function() with M;
+
+main() {}
diff --git a/pkg/front_end/testcases/general/issue48919.dart.textual_outline.expect b/pkg/front_end/testcases/general/issue48919.dart.textual_outline.expect
new file mode 100644
index 0000000..21a461f
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart.textual_outline.expect
@@ -0,0 +1,3 @@
+mixin M {}
+class A = void Function() with M;
+main() {}
diff --git a/pkg/front_end/testcases/general/issue48919.dart.weak.expect b/pkg/front_end/testcases/general/issue48919.dart.weak.expect
new file mode 100644
index 0000000..ac31d73
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart.weak.expect
@@ -0,0 +1,19 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
+// class A = void Function() with M;
+//                ^
+//
+import self as self;
+import "dart:core" as core;
+
+abstract class M extends core::Object /*isMixinDeclaration*/  {
+}
+class A = core::Object with self::M /*hasConstConstructor*/  {
+  const synthetic constructor •() → self::A
+    : super core::Object::•()
+    ;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/general/issue48919.dart.weak.modular.expect b/pkg/front_end/testcases/general/issue48919.dart.weak.modular.expect
new file mode 100644
index 0000000..ac31d73
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart.weak.modular.expect
@@ -0,0 +1,19 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
+// class A = void Function() with M;
+//                ^
+//
+import self as self;
+import "dart:core" as core;
+
+abstract class M extends core::Object /*isMixinDeclaration*/  {
+}
+class A = core::Object with self::M /*hasConstConstructor*/  {
+  const synthetic constructor •() → self::A
+    : super core::Object::•()
+    ;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/general/issue48919.dart.weak.outline.expect b/pkg/front_end/testcases/general/issue48919.dart.weak.outline.expect
new file mode 100644
index 0000000..10edd8f
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart.weak.outline.expect
@@ -0,0 +1,20 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
+// class A = void Function() with M;
+//                ^
+//
+import self as self;
+import "dart:core" as core;
+
+abstract class M extends core::Object /*isMixinDeclaration*/  {
+}
+class A = core::Object with self::M /*hasConstConstructor*/  {
+  const synthetic constructor •() → self::A
+    : super core::Object::•()
+    ;
+}
+static method main() → dynamic
+  ;
diff --git a/pkg/front_end/testcases/general/issue48919.dart.weak.transformed.expect b/pkg/front_end/testcases/general/issue48919.dart.weak.transformed.expect
new file mode 100644
index 0000000..4683e8a
--- /dev/null
+++ b/pkg/front_end/testcases/general/issue48919.dart.weak.transformed.expect
@@ -0,0 +1,19 @@
+library /*isNonNullableByDefault*/;
+//
+// Problems in library:
+//
+// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
+// class A = void Function() with M;
+//                ^
+//
+import self as self;
+import "dart:core" as core;
+
+abstract class M extends core::Object /*isMixinDeclaration*/  {
+}
+class A extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/  {
+  const synthetic constructor •() → self::A
+    : super core::Object::•()
+    ;
+}
+static method main() → dynamic {}
diff --git a/pkg/front_end/testcases/textual_outline.status b/pkg/front_end/testcases/textual_outline.status
index 259a964..7f8673a 100644
--- a/pkg/front_end/testcases/textual_outline.status
+++ b/pkg/front_end/testcases/textual_outline.status
@@ -98,6 +98,7 @@
 general/issue47922: FormatterCrash
 general/issue48487: FormatterCrash
 general/issue48487b: FormatterCrash
+general/issue48919: FormatterCrash
 general/issue_46886: FormatterCrash
 general/macro_class: FormatterCrash
 general/many_errors2: FormatterCrash