From aa9b83eefce99b3647338ab64fcfe50094a1dfc5 Mon Sep 17 00:00:00 2001 From: Chloe Stefantsova Date: Wed, 11 May 2022 09:27:45 +0000 Subject: [PATCH] [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 Reviewed-by: Johnni Winther --- .../fasta/source/source_library_builder.dart | 17 ++++++++++++++-- .../testcases/general/issue48919.dart | 8 ++++++++ .../issue48919.dart.textual_outline.expect | 3 +++ .../general/issue48919.dart.weak.expect | 19 ++++++++++++++++++ .../issue48919.dart.weak.modular.expect | 19 ++++++++++++++++++ .../issue48919.dart.weak.outline.expect | 20 +++++++++++++++++++ .../issue48919.dart.weak.transformed.expect | 19 ++++++++++++++++++ .../testcases/textual_outline.status | 1 + 8 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 pkg/front_end/testcases/general/issue48919.dart create mode 100644 pkg/front_end/testcases/general/issue48919.dart.textual_outline.expect create mode 100644 pkg/front_end/testcases/general/issue48919.dart.weak.expect create mode 100644 pkg/front_end/testcases/general/issue48919.dart.weak.modular.expect create mode 100644 pkg/front_end/testcases/general/issue48919.dart.weak.outline.expect create mode 100644 pkg/front_end/testcases/general/issue48919.dart.weak.transformed.expect 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 77c6eaab530..53fa58e0b8e 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 @@ 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; diff --git a/pkg/front_end/testcases/general/issue48919.dart b/pkg/front_end/testcases/general/issue48919.dart new file mode 100644 index 00000000000..9bec7cc552a --- /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 00000000000..21a461f17f0 --- /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 00000000000..ac31d73e778 --- /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 00000000000..ac31d73e778 --- /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 00000000000..10edd8fb552 --- /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 00000000000..4683e8af0d9 --- /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 259a964ec95..7f8673a1f01 100644 --- a/pkg/front_end/testcases/textual_outline.status +++ b/pkg/front_end/testcases/textual_outline.status @@ -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