Skip to content

Commit aa9b83e

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
[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 #48919 Change-Id: I57d223ee7914d0227baa3a4ef5733bb8055fa2c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244240 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent c54ade0 commit aa9b83e

8 files changed

+104
-2
lines changed

pkg/front_end/lib/src/fasta/source/source_library_builder.dart

+15-2
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,18 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
21492149
/// 1. `_Named&S&M1`
21502150
/// 2. `_Named&S&M1&M2`
21512151
/// 3. `Named`.
2152-
String runningName = extractName(supertype.name);
2152+
Object nameSourceForExtraction;
2153+
if (supertype.name == null) {
2154+
assert(supertype is FunctionTypeBuilder);
2155+
2156+
// Function types don't have names, and we can supply any string that
2157+
// doesn't have to be unique. The actual supertype of the mixin will
2158+
// not be built in that case.
2159+
nameSourceForExtraction = "";
2160+
} else {
2161+
nameSourceForExtraction = supertype.name!;
2162+
}
2163+
String runningName = extractName(nameSourceForExtraction);
21532164

21542165
/// True when we're building a named mixin application. Notice that for
21552166
/// the `Named` example above, this is only true on the last
@@ -5245,7 +5256,9 @@ Uri computeLibraryUri(Builder declaration) {
52455256
declaration.charOffset, declaration.fileUri);
52465257
}
52475258

5248-
String extractName(name) => name is QualifiedName ? name.name : name;
5259+
String extractName(Object name) {
5260+
return name is QualifiedName ? name.name : name as String;
5261+
}
52495262

52505263
class PostponedProblem {
52515264
final Message message;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
mixin M {}
6+
class A = void Function() with M;
7+
8+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mixin M {}
2+
class A = void Function() with M;
3+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
6+
// class A = void Function() with M;
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
abstract class M extends core::Object /*isMixinDeclaration*/ {
13+
}
14+
class A = core::Object with self::M /*hasConstConstructor*/ {
15+
const synthetic constructor •() → self::A
16+
: super core::Object::•()
17+
;
18+
}
19+
static method main() → dynamic {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
6+
// class A = void Function() with M;
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
abstract class M extends core::Object /*isMixinDeclaration*/ {
13+
}
14+
class A = core::Object with self::M /*hasConstConstructor*/ {
15+
const synthetic constructor •() → self::A
16+
: super core::Object::•()
17+
;
18+
}
19+
static method main() → dynamic {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
6+
// class A = void Function() with M;
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
abstract class M extends core::Object /*isMixinDeclaration*/ {
13+
}
14+
class A = core::Object with self::M /*hasConstConstructor*/ {
15+
const synthetic constructor •() → self::A
16+
: super core::Object::•()
17+
;
18+
}
19+
static method main() → dynamic
20+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
library /*isNonNullableByDefault*/;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/general/issue48919.dart:6:16: Error: Can't use a function type as supertype.
6+
// class A = void Function() with M;
7+
// ^
8+
//
9+
import self as self;
10+
import "dart:core" as core;
11+
12+
abstract class M extends core::Object /*isMixinDeclaration*/ {
13+
}
14+
class A extends core::Object implements self::M /*isEliminatedMixin,hasConstConstructor*/ {
15+
const synthetic constructor •() → self::A
16+
: super core::Object::•()
17+
;
18+
}
19+
static method main() → dynamic {}

pkg/front_end/testcases/textual_outline.status

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ general/issue47728_3: FormatterCrash
9898
general/issue47922: FormatterCrash
9999
general/issue48487: FormatterCrash
100100
general/issue48487b: FormatterCrash
101+
general/issue48919: FormatterCrash
101102
general/issue_46886: FormatterCrash
102103
general/macro_class: FormatterCrash
103104
general/many_errors2: FormatterCrash

0 commit comments

Comments
 (0)