Skip to content

Commit

Permalink
Improve messages involving empty cycles
Browse files Browse the repository at this point in the history
Change-Id: I4a6732bcce9ddb98cd00e60e8d46fae1dd4b9599
Reviewed-on: https://dart-review.googlesource.com/76500
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
  • Loading branch information
peter-ahe-google authored and commit-bot@chromium.org committed Sep 26, 2018
1 parent 48d1b5e commit a3aa0c1
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
46 changes: 46 additions & 0 deletions pkg/front_end/lib/src/fasta/fasta_codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message Function(String name)> codeDirectCycleInTypeVariables =
const Code<Message Function(String name)>(
"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<Message Function(String name)>
templateDirectCyclicClassHierarchy =
const Template<Message Function(String name)>(
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<Message Function(String name)> codeDirectCyclicClassHierarchy =
const Code<Message Function(String name)>(
"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<Null> codeDirectiveAfterDeclaration =
messageDirectiveAfterDeclaration;
Expand Down
12 changes: 6 additions & 6 deletions pkg/front_end/lib/src/fasta/source/outline_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import '../fasta_codes.dart'
messageStaticConstructor,
messageTypedefNotFunction,
templateCycleInTypeVariables,
templateDirectCycleInTypeVariables,
templateDuplicatedParameterName,
templateDuplicatedParameterNameCause,
templateOperatorMinusParameterMismatch,
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/front_end/lib/src/fasta/source/source_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import '../fasta_codes.dart'
templateIllegalMixinDueToConstructorsCause,
templateInternalProblemUriMissingScheme,
templateSourceOutlineSummary,
templateDirectCyclicClassHierarchy,
templateUntranslatableUri;

import '../fasta_codes.dart' as fasta_codes;
Expand Down Expand Up @@ -584,9 +585,14 @@ class SourceLoader<L> extends Loader<L> {
.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
Expand Down
4 changes: 3 additions & 1 deletion pkg/front_end/messages.status
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions pkg/front_end/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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<A extends B, B extends A>() {}"

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<A extends A>() {}"

Expand Down

0 comments on commit a3aa0c1

Please sign in to comment.