Skip to content

Commit

Permalink
Move 5 more Hints to be Warnings, INVALID_*
Browse files Browse the repository at this point in the history
Bug: #50796
Change-Id: I116c957801ab873f2c7bb725008daf80564e7526
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280133
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
  • Loading branch information
srawlins authored and Commit Queue committed Feb 2, 2023
1 parent 7927c5b commit efa27cc
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1432,14 +1432,6 @@ HintCode.INVALID_NON_VIRTUAL_ANNOTATION:
status: hasFix
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER:
status: noFix
HintCode.INVALID_REQUIRED_NAMED_PARAM:
status: hasFix
HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM:
status: hasFix
HintCode.INVALID_REQUIRED_POSITIONAL_PARAM:
status: hasFix
HintCode.INVALID_SEALED_ANNOTATION:
status: hasFix
HintCode.INVALID_USE_OF_INTERNAL_MEMBER:
status: noFix
HintCode.INVALID_USE_OF_PROTECTED_MEMBER:
Expand Down Expand Up @@ -1524,10 +1516,6 @@ HintCode.RETURN_OF_DO_NOT_STORE:
status: needsFix
notes: |-
The fix is to add the annotation to the enclosing function.
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR:
status: noFix
HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR:
status: noFix
HintCode.STRICT_RAW_TYPE:
status: needsFix
notes: |-
Expand Down Expand Up @@ -2778,6 +2766,18 @@ WarningCode.INVALID_LANGUAGE_VERSION_OVERRIDE_TWO_SLASHES:
notes: |-
If we can identify enough information to do so, the fix is to rewrite the
comment into a valid form.
WarningCode.INVALID_REQUIRED_NAMED_PARAM:
status: hasFix
WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM:
status: hasFix
WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM:
status: hasFix
WarningCode.INVALID_SEALED_ANNOTATION:
status: hasFix
WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR:
status: noFix
WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR:
status: noFix
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
status: hasFix
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT:
Expand Down
24 changes: 12 additions & 12 deletions pkg/analysis_server/lib/src/services/correction/fix_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1366,18 +1366,6 @@ class FixProcessor extends BaseProcessor {
HintCode.INVALID_NON_VIRTUAL_ANNOTATION: [
RemoveAnnotation.new,
],
HintCode.INVALID_REQUIRED_NAMED_PARAM: [
RemoveAnnotation.new,
],
HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM: [
RemoveAnnotation.new,
],
HintCode.INVALID_REQUIRED_POSITIONAL_PARAM: [
RemoveAnnotation.new,
],
HintCode.INVALID_SEALED_ANNOTATION: [
RemoveAnnotation.new,
],
HintCode.INVALID_VISIBILITY_ANNOTATION: [
RemoveAnnotation.new,
],
Expand Down Expand Up @@ -1563,6 +1551,18 @@ class FixProcessor extends BaseProcessor {
WarningCode.INVALID_FACTORY_ANNOTATION: [
RemoveAnnotation.new,
],
WarningCode.INVALID_REQUIRED_NAMED_PARAM: [
RemoveAnnotation.new,
],
WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM: [
RemoveAnnotation.new,
],
WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM: [
RemoveAnnotation.new,
],
WarningCode.INVALID_SEALED_ANNOTATION: [
RemoveAnnotation.new,
],
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT: [
UpdateSdkConstraints.version_2_2_2,
],
Expand Down
69 changes: 0 additions & 69 deletions pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,53 +353,6 @@ class HintCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);

/// This hint is generated anywhere where `@required` annotates a named
/// parameter with a default value.
///
/// Parameters:
/// 0: the name of the member
static const HintCode INVALID_REQUIRED_NAMED_PARAM = HintCode(
'INVALID_REQUIRED_NAMED_PARAM',
"The type parameter '{0}' is annotated with @required but only named "
"parameters without a default value can be annotated with it.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@required` annotates an optional
/// positional parameter.
///
/// Parameters:
/// 0: the name of the member
static const HintCode INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM = HintCode(
'INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM',
"Incorrect use of the annotation @required on the optional positional "
"parameter '{0}'. Optional positional parameters cannot be required.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@required` annotates a non optional
/// positional parameter.
///
/// Parameters:
/// 0: the name of the member
static const HintCode INVALID_REQUIRED_POSITIONAL_PARAM = HintCode(
'INVALID_REQUIRED_POSITIONAL_PARAM',
"Redundant use of the annotation @required on the required positional "
"parameter '{0}'.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@sealed` annotates something other
/// than a class.
///
/// No parameters.
static const HintCode INVALID_SEALED_ANNOTATION = HintCode(
'INVALID_SEALED_ANNOTATION',
"The annotation '@sealed' can only be applied to classes.",
correctionMessage: "Try removing the '@sealed' annotation.",
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the name of the member
static const HintCode INVALID_USE_OF_INTERNAL_MEMBER = HintCode(
Expand Down Expand Up @@ -775,28 +728,6 @@ class HintCode extends AnalyzerErrorCode {
hasPublishedDocs: true,
);

/// Parameters:
/// 0: the return type as declared in the return statement
/// 1: the expected return type as defined by the type of the Future
static const HintCode RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR = HintCode(
'INVALID_RETURN_TYPE_FOR_CATCH_ERROR',
"A value of type '{0}' can't be returned by the 'onError' handler because "
"it must be assignable to '{1}'.",
hasPublishedDocs: true,
uniqueName: 'RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR',
);

/// Parameters:
/// 0: the return type of the function
/// 1: the expected return type as defined by the type of the Future
static const HintCode RETURN_TYPE_INVALID_FOR_CATCH_ERROR = HintCode(
'INVALID_RETURN_TYPE_FOR_CATCH_ERROR',
"The return type '{0}' isn't assignable to '{1}', as required by "
"'Future.catchError'.",
hasPublishedDocs: true,
uniqueName: 'RETURN_TYPE_INVALID_FOR_CATCH_ERROR',
);

/// When "strict-raw-types" is enabled, "raw types" must have type arguments.
///
/// A "raw type" is a type name that does not use inference to fill in missing
Expand Down
12 changes: 7 additions & 5 deletions pkg/analyzer/lib/src/error/best_practices_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
} else if (element.isSealed) {
if (!(parent is ClassDeclaration || parent is ClassTypeAlias)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_SEALED_ANNOTATION, node);
WarningCode.INVALID_SEALED_ANNOTATION, node);
}
} else if (element.isVisibleForTemplate ||
element.isVisibleForTesting ||
Expand Down Expand Up @@ -1565,19 +1565,21 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
.where((p) => p.declaredElement!.defaultValueCode != null);
for (final param in nonNamedParamsWithRequired.where((p) => p.isOptional)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM,
WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM,
param,
[_formalParameterNameOrEmpty(param)]);
}
for (final param in nonNamedParamsWithRequired.where((p) => p.isRequired)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_REQUIRED_POSITIONAL_PARAM,
WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM,
param,
[_formalParameterNameOrEmpty(param)]);
}
for (final param in namedParamsWithRequiredAndDefault) {
_errorReporter.reportErrorForNode(HintCode.INVALID_REQUIRED_NAMED_PARAM,
param, [_formalParameterNameOrEmpty(param)]);
_errorReporter.reportErrorForNode(
WarningCode.INVALID_REQUIRED_NAMED_PARAM,
param,
[_formalParameterNameOrEmpty(param)]);
}
}

Expand Down
71 changes: 71 additions & 0 deletions pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5984,6 +5984,54 @@ class WarningCode extends AnalyzerErrorCode {
uniqueName: 'INVALID_LANGUAGE_VERSION_OVERRIDE_TWO_SLASHES',
);

/// This hint is generated anywhere where `@required` annotates a named
/// parameter with a default value.
///
/// Parameters:
/// 0: the name of the member
static const WarningCode INVALID_REQUIRED_NAMED_PARAM = WarningCode(
'INVALID_REQUIRED_NAMED_PARAM',
"The type parameter '{0}' is annotated with @required but only named "
"parameters without a default value can be annotated with it.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@required` annotates an optional
/// positional parameter.
///
/// Parameters:
/// 0: the name of the member
static const WarningCode INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM =
WarningCode(
'INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM',
"Incorrect use of the annotation @required on the optional positional "
"parameter '{0}'. Optional positional parameters cannot be required.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@required` annotates a non optional
/// positional parameter.
///
/// Parameters:
/// 0: the name of the member
static const WarningCode INVALID_REQUIRED_POSITIONAL_PARAM = WarningCode(
'INVALID_REQUIRED_POSITIONAL_PARAM',
"Redundant use of the annotation @required on the required positional "
"parameter '{0}'.",
correctionMessage: "Remove @required.",
);

/// This hint is generated anywhere where `@sealed` annotates something other
/// than a class.
///
/// No parameters.
static const WarningCode INVALID_SEALED_ANNOTATION = WarningCode(
'INVALID_SEALED_ANNOTATION',
"The annotation '@sealed' can only be applied to classes.",
correctionMessage: "Try removing the '@sealed' annotation.",
hasPublishedDocs: true,
);

/// This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR].
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR =
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
Expand All @@ -5992,6 +6040,29 @@ class WarningCode extends AnalyzerErrorCode {
static const HintCode OVERRIDE_ON_NON_OVERRIDING_FIELD =
HintCode.OVERRIDE_ON_NON_OVERRIDING_FIELD;

/// Parameters:
/// 0: the return type as declared in the return statement
/// 1: the expected return type as defined by the type of the Future
static const WarningCode RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR =
WarningCode(
'INVALID_RETURN_TYPE_FOR_CATCH_ERROR',
"A value of type '{0}' can't be returned by the 'onError' handler because "
"it must be assignable to '{1}'.",
hasPublishedDocs: true,
uniqueName: 'RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR',
);

/// Parameters:
/// 0: the return type of the function
/// 1: the expected return type as defined by the type of the Future
static const WarningCode RETURN_TYPE_INVALID_FOR_CATCH_ERROR = WarningCode(
'INVALID_RETURN_TYPE_FOR_CATCH_ERROR',
"The return type '{0}' isn't assignable to '{1}', as required by "
"'Future.catchError'.",
hasPublishedDocs: true,
uniqueName: 'RETURN_TYPE_INVALID_FOR_CATCH_ERROR',
);

/// Parameters:
/// 0: the name of the class
static const WarningCode SDK_VERSION_ASYNC_EXPORTED_FROM_CORE = WarningCode(
Expand Down
12 changes: 6 additions & 6 deletions pkg/analyzer/lib/src/error/error_code_values.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,6 @@ const List<ErrorCode> errorCodeValues = [
HintCode.INVALID_LITERAL_ANNOTATION,
HintCode.INVALID_NON_VIRTUAL_ANNOTATION,
HintCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER,
HintCode.INVALID_REQUIRED_NAMED_PARAM,
HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM,
HintCode.INVALID_REQUIRED_POSITIONAL_PARAM,
HintCode.INVALID_SEALED_ANNOTATION,
HintCode.INVALID_USE_OF_INTERNAL_MEMBER,
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
HintCode.INVALID_USE_OF_VISIBLE_FOR_OVERRIDING_MEMBER,
Expand Down Expand Up @@ -643,8 +639,6 @@ const List<ErrorCode> errorCodeValues = [
HintCode.REMOVED_LINT_USE,
HintCode.REPLACED_LINT_USE,
HintCode.RETURN_OF_DO_NOT_STORE,
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR,
HintCode.STRICT_RAW_TYPE,
HintCode.SUBTYPE_OF_SEALED_CLASS,
HintCode.TEXT_DIRECTION_CODE_POINT_IN_COMMENT,
Expand Down Expand Up @@ -980,6 +974,12 @@ const List<ErrorCode> errorCodeValues = [
WarningCode.INVALID_LANGUAGE_VERSION_OVERRIDE_PREFIX,
WarningCode.INVALID_LANGUAGE_VERSION_OVERRIDE_TRAILING_CHARACTERS,
WarningCode.INVALID_LANGUAGE_VERSION_OVERRIDE_TWO_SLASHES,
WarningCode.INVALID_REQUIRED_NAMED_PARAM,
WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM,
WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM,
WarningCode.INVALID_SEALED_ANNOTATION,
WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR,
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/error/error_handler_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ErrorHandlerVerifier {
DartType expectedType, DartType functionReturnType, Expression callback) {
if (!_typeSystem.isAssignableTo(functionReturnType, expectedType)) {
_errorReporter.reportErrorForNode(
HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR,
WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR,
callback,
[functionReturnType, expectedType],
);
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/error/return_type_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ReturnTypeVerifier {
void reportTypeError() {
if (enclosingExecutable.catchErrorOnErrorReturnType != null) {
_errorReporter.reportErrorForNode(
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
expression,
[S, T],
);
Expand Down Expand Up @@ -275,7 +275,7 @@ class ReturnTypeVerifier {
void reportTypeError() {
if (enclosingExecutable.catchErrorOnErrorReturnType != null) {
_errorReporter.reportErrorForNode(
HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR,
expression,
[S, T],
);
Expand Down
Loading

0 comments on commit efa27cc

Please sign in to comment.