CQ. Deprecate 'reportErrorForName', use 'atConstructorDeclaration' instead.

Change-Id: Ife3cdfd53551f12aa1b0dc6a223ae91e248ed33e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383444
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2024-09-03 20:22:37 +00:00
committed by Commit Queue
parent b1249ff182
commit e41b531a59
4 changed files with 46 additions and 36 deletions
+29 -24
View File
@@ -67,6 +67,35 @@ class ErrorReporter {
Source get source => _source;
/// Report a diagnostic with the given [errorCode] and [arguments].
/// The location of the diagnostic will be the name of the [node].
void atConstructorDeclaration(
ConstructorDeclaration node,
ErrorCode errorCode, {
List<Object>? arguments,
List<DiagnosticMessage>? contextMessages,
Object? data,
}) {
// TODO(brianwilkerson): Consider extending this method to take any
// declaration and compute the correct range for the name of that
// declaration. This might make it easier to be consistent.
if (node.name case var nameToken?) {
var offset = node.returnType.offset;
atOffset(
offset: offset,
length: nameToken.end - offset,
errorCode: errorCode,
arguments: arguments,
);
} else {
atNode(
node.returnType,
errorCode,
arguments: arguments,
);
}
}
/// Report an error with the given [errorCode] and [arguments].
/// The [element] is used to compute the location of the error.
void atElement(
@@ -211,30 +240,6 @@ class ErrorReporter {
);
}
/// Report a diagnostic with the given [code] and [arguments]. The
/// location of the diagnostic will be the name of the [constructor].
void reportErrorForName(ErrorCode code, ConstructorDeclaration constructor,
{List<Object>? arguments}) {
// TODO(brianwilkerson): Consider extending this method to take any
// declaration and compute the correct range for the name of that
// declaration. This might make it easier to be consistent.
if (constructor.name != null) {
var offset = constructor.returnType.offset;
atOffset(
offset: offset,
length: constructor.name!.end - offset,
errorCode: code,
arguments: arguments,
);
} else {
atNode(
constructor.returnType,
code,
arguments: arguments,
);
}
}
/// Report an error with the given [errorCode] and [arguments].
/// The [node] is used to compute the location of the error.
@Deprecated('Use atNode() instead')
@@ -341,12 +341,16 @@ class MemberDuplicateDefinitionVerifier {
}
if (!constructorNames.add(name)) {
if (name.isEmpty) {
_errorReporter.reportErrorForName(
CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT, member);
_errorReporter.atConstructorDeclaration(
member,
CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_DEFAULT,
);
} else {
_errorReporter.reportErrorForName(
CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME, member,
arguments: [name]);
_errorReporter.atConstructorDeclaration(
member,
CompileTimeErrorCode.DUPLICATE_CONSTRUCTOR_NAME,
arguments: [name],
);
}
}
case FieldDeclaration():
@@ -2909,9 +2909,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (classElement is! ClassElement || !classElement.hasNonFinalField) {
return;
}
errorReporter.reportErrorForName(
CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD,
constructor);
errorReporter.atConstructorDeclaration(
constructor,
CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD,
);
}
/// Verify that the given 'const' instance creation [expression] is not
@@ -4710,9 +4711,9 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
if (_enclosingClass is EnumElement &&
node.constKeyword == null &&
node.factoryKeyword == null) {
errorReporter.reportErrorForName(
CompileTimeErrorCode.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR,
errorReporter.atConstructorDeclaration(
node,
CompileTimeErrorCode.NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR,
);
}
}
+2 -2
View File
@@ -569,9 +569,9 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
}
}
if (errorNode is ConstructorDeclaration) {
errorReporter.reportErrorForName(
errorCode,
errorReporter.atConstructorDeclaration(
errorNode,
errorCode,
arguments: [returnType],
);
} else if (errorNode is BlockFunctionBody) {