mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:36:59 +00:00
Fix error messages that don't properly name members.
The error messages for INVALID_NON_VIRTUAL_ANNOTATION and INVALID_SEALED_ANNOTATION appeared to reference the name of the erroneously declared member, with messages like "The member '{0}' can't be '@nonVirtual' because it isn't a concrete instance member.", however the actual text that was substituted into the error message wasn't the name of the member, but rather the name of the element declaring the annotation. So the error message would always be "The member 'nonVirtual' can't be '@nonVirtual' because it isn't a concrete instance member.", which was unhelpful and confusing. Rather than fix the code to come up with the correct name of the member (which would have been challenging, because the target of the annotation could be an extension without a name, and wouldn't have been that useful anyway, since the error location points to the member), I've simply rephrased the error messages so that they don't name the member in question. Change-Id: I34f74e04607e16211b357429820c0336e0a03059 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216563 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
914f100be4
commit
a5714b1290
|
@ -1232,12 +1232,11 @@ class HintCode extends AnalyzerErrorCode {
|
|||
* This hint is generated anywhere where `@nonVirtual` annotates something
|
||||
* other than a non-abstract instance member in a class or mixin.
|
||||
*
|
||||
* Parameters:
|
||||
* 0: the name of the member
|
||||
* No Parameters.
|
||||
*/
|
||||
static const HintCode INVALID_NON_VIRTUAL_ANNOTATION = HintCode(
|
||||
'INVALID_NON_VIRTUAL_ANNOTATION',
|
||||
"The member '{0}' can't be '@nonVirtual' because it isn't a concrete instance member.",
|
||||
"The annotation '@nonVirtual' can only be applied to a concrete instance member.",
|
||||
correctionMessage: "Try removing @nonVirtual.",
|
||||
);
|
||||
|
||||
|
@ -1297,12 +1296,11 @@ class HintCode extends AnalyzerErrorCode {
|
|||
* This hint is generated anywhere where `@sealed` annotates something other
|
||||
* than a class.
|
||||
*
|
||||
* Parameters:
|
||||
* 0: the name of the member
|
||||
* No parameters.
|
||||
*/
|
||||
static const HintCode INVALID_SEALED_ANNOTATION = HintCode(
|
||||
'INVALID_SEALED_ANNOTATION',
|
||||
"The member '{0}' is annotated with '@sealed' but only classes can be annotated with it.",
|
||||
"The annotation '@sealed' can only be applied to classes.",
|
||||
correctionMessage: "Remove @sealed.",
|
||||
);
|
||||
|
||||
|
|
|
@ -201,29 +201,23 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
|
|||
if (parent is FieldDeclaration) {
|
||||
if (parent.isStatic) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION,
|
||||
node,
|
||||
[node.element!.name]);
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION, node);
|
||||
}
|
||||
} else if (parent is MethodDeclaration) {
|
||||
if (parent.parent is ExtensionDeclaration ||
|
||||
parent.isStatic ||
|
||||
parent.isAbstract) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION,
|
||||
node,
|
||||
[node.element!.name]);
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION, node);
|
||||
}
|
||||
} else {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION,
|
||||
node,
|
||||
[node.element!.name]);
|
||||
HintCode.INVALID_NON_VIRTUAL_ANNOTATION, node);
|
||||
}
|
||||
} else if (element.isSealed == true) {
|
||||
if (!(parent is ClassDeclaration || parent is ClassTypeAlias)) {
|
||||
_errorReporter.reportErrorForNode(
|
||||
HintCode.INVALID_SEALED_ANNOTATION, node, [node.element!.name]);
|
||||
HintCode.INVALID_SEALED_ANNOTATION, node);
|
||||
}
|
||||
} else if (element.isVisibleForTemplate == true ||
|
||||
element.isVisibleForTesting == true ||
|
||||
|
|
|
@ -14959,14 +14959,13 @@ HintCode:
|
|||
var x;
|
||||
```
|
||||
INVALID_NON_VIRTUAL_ANNOTATION:
|
||||
problemMessage: "The member '{0}' can't be '@nonVirtual' because it isn't a concrete instance member."
|
||||
problemMessage: "The annotation '@nonVirtual' can only be applied to a concrete instance member."
|
||||
correctionMessage: Try removing @nonVirtual.
|
||||
comment: |-
|
||||
This hint is generated anywhere where `@nonVirtual` annotates something
|
||||
other than a non-abstract instance member in a class or mixin.
|
||||
|
||||
Parameters:
|
||||
0: the name of the member
|
||||
No Parameters.
|
||||
INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER:
|
||||
problemMessage: "The member '{0}' is declared non-virtual in '{1}' and can't be overridden in subclasses."
|
||||
comment: |-
|
||||
|
@ -15070,14 +15069,13 @@ HintCode:
|
|||
}
|
||||
```
|
||||
INVALID_SEALED_ANNOTATION:
|
||||
problemMessage: "The member '{0}' is annotated with '@sealed' but only classes can be annotated with it."
|
||||
problemMessage: "The annotation '@sealed' can only be applied to classes."
|
||||
correctionMessage: Remove @sealed.
|
||||
comment: |-
|
||||
This hint is generated anywhere where `@sealed` annotates something other
|
||||
than a class.
|
||||
|
||||
Parameters:
|
||||
0: the name of the member
|
||||
No parameters.
|
||||
INVALID_USE_OF_INTERNAL_MEMBER:
|
||||
problemMessage: "The member '{0}' can only be used within its package."
|
||||
comment: |-
|
||||
|
|
Loading…
Reference in a new issue