[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>
This commit is contained in:
Chloe Stefantsova 2022-05-11 09:27:45 +00:00 committed by Commit Bot
parent c54ade0cce
commit aa9b83eefc
8 changed files with 104 additions and 2 deletions

View file

@ -2149,7 +2149,18 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
/// 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 @@ Uri computeLibraryUri(Builder declaration) {
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;

View file

@ -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() {}

View file

@ -0,0 +1,3 @@
mixin M {}
class A = void Function() with M;
main() {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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
;

View file

@ -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 {}

View file

@ -98,6 +98,7 @@ general/issue47728_3: FormatterCrash
general/issue47922: FormatterCrash
general/issue48487: FormatterCrash
general/issue48487b: FormatterCrash
general/issue48919: FormatterCrash
general/issue_46886: FormatterCrash
general/macro_class: FormatterCrash
general/many_errors2: FormatterCrash