Skip to content

Commit

Permalink
[cfe] Require a non-null name for mixin supertypes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
chloestefantsova authored and Commit Bot committed May 11, 2022
1 parent c54ade0 commit aa9b83e
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/front_end/lib/src/fasta/source/source_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions pkg/front_end/testcases/general/issue48919.dart
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mixin M {}
class A = void Function() with M;
main() {}
19 changes: 19 additions & 0 deletions pkg/front_end/testcases/general/issue48919.dart.weak.expect
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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
;
Original file line number Diff line number Diff line change
@@ -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 {}
1 change: 1 addition & 0 deletions pkg/front_end/testcases/textual_outline.status
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa9b83e

Please sign in to comment.