From a3aa0c18fb3e6be5488611e70d93e39df2e78cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20von=20der=20Ahe=CC=81?= Date: Wed, 26 Sep 2018 07:45:12 +0000 Subject: [PATCH] Improve messages involving empty cycles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4a6732bcce9ddb98cd00e60e8d46fae1dd4b9599 Reviewed-on: https://dart-review.googlesource.com/76500 Commit-Queue: Peter von der Ahé Reviewed-by: Jens Johansen --- .../lib/src/fasta/fasta_codes_generated.dart | 46 +++++++++++++++++++ .../lib/src/fasta/source/outline_builder.dart | 12 ++--- .../lib/src/fasta/source/source_loader.dart | 12 +++-- pkg/front_end/messages.status | 4 +- pkg/front_end/messages.yaml | 22 +++++++++ 5 files changed, 86 insertions(+), 10 deletions(-) diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart index e6f3aacb65f8b..d70040ccca67c 100644 --- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart +++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart @@ -1942,6 +1942,52 @@ ${num3} ms/libraries.""", }); } +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Template< + Message Function( + String + name)> templateDirectCycleInTypeVariables = const Template< + Message Function(String name)>( + messageTemplate: r"""Type '#name' can't use itself as a bound.""", + tipTemplate: + r"""Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle.""", + withArguments: _withArgumentsDirectCycleInTypeVariables); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Code codeDirectCycleInTypeVariables = + const Code( + "DirectCycleInTypeVariables", templateDirectCycleInTypeVariables, + analyzerCode: "TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND"); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +Message _withArgumentsDirectCycleInTypeVariables(String name) { + return new Message(codeDirectCycleInTypeVariables, + message: """Type '${name}' can't use itself as a bound.""", + tip: + """Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle.""", + arguments: {'name': name}); +} + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Template + templateDirectCyclicClassHierarchy = + const Template( + messageTemplate: r"""'#name' can't use itself as a supertype.""", + withArguments: _withArgumentsDirectCyclicClassHierarchy); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +const Code codeDirectCyclicClassHierarchy = + const Code( + "DirectCyclicClassHierarchy", templateDirectCyclicClassHierarchy, + analyzerCode: "RECURSIVE_INTERFACE_INHERITANCE"); + +// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. +Message _withArgumentsDirectCyclicClassHierarchy(String name) { + return new Message(codeDirectCyclicClassHierarchy, + message: """'${name}' can't use itself as a supertype.""", + arguments: {'name': name}); +} + // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const Code codeDirectiveAfterDeclaration = messageDirectiveAfterDeclaration; diff --git a/pkg/front_end/lib/src/fasta/source/outline_builder.dart b/pkg/front_end/lib/src/fasta/source/outline_builder.dart index 73bb7c4a46526..4874302de34be 100644 --- a/pkg/front_end/lib/src/fasta/source/outline_builder.dart +++ b/pkg/front_end/lib/src/fasta/source/outline_builder.dart @@ -30,6 +30,7 @@ import '../fasta_codes.dart' messageStaticConstructor, messageTypedefNotFunction, templateCycleInTypeVariables, + templateDirectCycleInTypeVariables, templateDuplicatedParameterName, templateDuplicatedParameterNameCause, templateOperatorMinusParameterMismatch, @@ -1376,12 +1377,11 @@ class OutlineBuilder extends StackListener { via.add(bound.name); bound = typeVariablesByName[bound.bound.name]; } - String involvedString = via.join("', '"); - addProblem( - templateCycleInTypeVariables.withArguments( - builder.name, involvedString), - builder.charOffset, - builder.name.length); + Message message = via.isEmpty + ? templateDirectCycleInTypeVariables.withArguments(builder.name) + : templateCycleInTypeVariables.withArguments( + builder.name, via.join("', '")); + addProblem(message, builder.charOffset, builder.name.length); } } } diff --git a/pkg/front_end/lib/src/fasta/source/source_loader.dart b/pkg/front_end/lib/src/fasta/source/source_loader.dart index ac9aedbe313b9..098628601c119 100644 --- a/pkg/front_end/lib/src/fasta/source/source_loader.dart +++ b/pkg/front_end/lib/src/fasta/source/source_loader.dart @@ -73,6 +73,7 @@ import '../fasta_codes.dart' templateIllegalMixinDueToConstructorsCause, templateInternalProblemUriMissingScheme, templateSourceOutlineSummary, + templateDirectCyclicClassHierarchy, templateUntranslatableUri; import '../fasta_codes.dart' as fasta_codes; @@ -584,9 +585,14 @@ class SourceLoader extends Loader { .toList() ..sort()) .join("', '"); - messages[templateCyclicClassHierarchy - .withArguments(cls.fullNameForErrors, involvedString) - .withLocation(cls.fileUri, cls.charOffset, noLength)] = cls; + LocatedMessage message = involvedString.isEmpty + ? templateDirectCyclicClassHierarchy + .withArguments(cls.fullNameForErrors) + .withLocation(cls.fileUri, cls.charOffset, noLength) + : templateCyclicClassHierarchy + .withArguments(cls.fullNameForErrors, involvedString) + .withLocation(cls.fileUri, cls.charOffset, noLength); + messages[message] = cls; }); // Report all classes involved in a cycle, sorted to ensure stability as diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status index f85766975d464..3a84a54ee0ff5 100644 --- a/pkg/front_end/messages.status +++ b/pkg/front_end/messages.status @@ -88,7 +88,9 @@ CovariantAndStatic/script1: Fail CovariantAndStatic/script2: Fail CovariantMember/script1: Fail CovariantMember/script2: Fail -CyclicClassHierarchy/example: Fail +CycleInTypeVariables/script1: Fail # We report an error for each type variable involved in the cycle. +CyclicClassHierarchy/script1: Fail # We report an error for each class involved in the cycle. +CyclicClassHierarchy/script2: Fail # We report an error for each class involved in the cycle. CyclicTypedef/example: Fail DeferredAfterPrefix/example: Fail DeferredPrefixDuplicated/example: Fail diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index f3cfe7cd2c6bc..dd205181c4c1c 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -1663,6 +1663,21 @@ DuplicatedImportInType: CyclicClassHierarchy: template: "'#name' is a supertype of itself via '#string'." analyzerCode: RECURSIVE_INTERFACE_INHERITANCE + script: + - | + class A extends B {} + class B extends A {} + - | + class A implements B {} + class B implements A {} + +DirectCyclicClassHierarchy: + template: "'#name' can't use itself as a supertype." + analyzerCode: RECURSIVE_INTERFACE_INHERITANCE + script: + - "class C = Object with C;" + - "class C extends C {}" + - "class C implements C {}" ExtendingEnum: template: "'#name' is an enum and can't be extended or implemented." @@ -2841,6 +2856,13 @@ CycleInTypeVariables: template: "Type '#name' is a bound of itself via '#string'." tip: "Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle." analyzerCode: TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND + script: + - "foo() {}" + +DirectCycleInTypeVariables: + template: "Type '#name' can't use itself as a bound." + tip: "Try breaking the cycle by removing at least on of the 'extends' clauses in the cycle." + analyzerCode: TYPE_PARAMETER_SUPERTYPE_OF_ITS_BOUND script: - "foo() {}"