From efa27cc0d31d6fe6ed40eacd71a02ee5cc7c3cb6 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 2 Feb 2023 16:51:29 +0000 Subject: [PATCH] Move 5 more Hints to be Warnings, INVALID_* Bug: https://github.com/dart-lang/sdk/issues/50796 Change-Id: I116c957801ab873f2c7bb725008daf80564e7526 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280133 Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- .../services/correction/error_fix_status.yaml | 24 +- .../src/services/correction/fix_internal.dart | 24 +- .../lib/src/dart/error/hint_codes.g.dart | 69 ----- .../src/error/best_practices_verifier.dart | 12 +- pkg/analyzer/lib/src/error/codes.g.dart | 71 +++++ .../lib/src/error/error_code_values.g.dart | 12 +- .../lib/src/error/error_handler_verifier.dart | 2 +- .../lib/src/error/return_type_verifier.dart | 4 +- pkg/analyzer/messages.yaml | 262 +++++++++--------- .../invalid_required_named_param_test.dart | 4 +- ...quired_optional_positional_param_test.dart | 8 +- ...nvalid_required_positional_param_test.dart | 8 +- .../invalid_sealed_annotation_test.dart | 4 +- ...of_invalid_type_from_catch_error_test.dart | 8 +- ...urn_type_invalid_for_catch_error_test.dart | 4 +- 15 files changed, 260 insertions(+), 256 deletions(-) diff --git a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml index 57ef61939504..498e661fc423 100644 --- a/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml +++ b/pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml @@ -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: @@ -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: |- @@ -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: diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index 675ea61eb67f..c7eded846fc5 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -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, ], @@ -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, ], diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart index 850d06940059..45e78dfd67a2 100644 --- a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart +++ b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart @@ -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( @@ -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 diff --git a/pkg/analyzer/lib/src/error/best_practices_verifier.dart b/pkg/analyzer/lib/src/error/best_practices_verifier.dart index d0ce1bf0e9e7..cd57285669ec 100644 --- a/pkg/analyzer/lib/src/error/best_practices_verifier.dart +++ b/pkg/analyzer/lib/src/error/best_practices_verifier.dart @@ -232,7 +232,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor { } 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 || @@ -1565,19 +1565,21 @@ class BestPracticesVerifier extends RecursiveAstVisitor { .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)]); } } diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart index f18a0dfdd701..f01b3e4ab757 100644 --- a/pkg/analyzer/lib/src/error/codes.g.dart +++ b/pkg/analyzer/lib/src/error/codes.g.dart @@ -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; @@ -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( diff --git a/pkg/analyzer/lib/src/error/error_code_values.g.dart b/pkg/analyzer/lib/src/error/error_code_values.g.dart index 4be8d2bb7bef..65a0046e1934 100644 --- a/pkg/analyzer/lib/src/error/error_code_values.g.dart +++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart @@ -606,10 +606,6 @@ const List 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, @@ -643,8 +639,6 @@ const List 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, @@ -980,6 +974,12 @@ const List 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, diff --git a/pkg/analyzer/lib/src/error/error_handler_verifier.dart b/pkg/analyzer/lib/src/error/error_handler_verifier.dart index aaa29aa213f1..ceebfcabe692 100644 --- a/pkg/analyzer/lib/src/error/error_handler_verifier.dart +++ b/pkg/analyzer/lib/src/error/error_handler_verifier.dart @@ -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], ); diff --git a/pkg/analyzer/lib/src/error/return_type_verifier.dart b/pkg/analyzer/lib/src/error/return_type_verifier.dart index 2ae92c7ed08a..f28c22f5b8a2 100644 --- a/pkg/analyzer/lib/src/error/return_type_verifier.dart +++ b/pkg/analyzer/lib/src/error/return_type_verifier.dart @@ -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], ); @@ -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], ); diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml index 2e9a042f53f4..a665499f6dab 100644 --- a/pkg/analyzer/messages.yaml +++ b/pkg/analyzer/messages.yaml @@ -18656,137 +18656,6 @@ HintCode: void m() {} } ``` - INVALID_REQUIRED_NAMED_PARAM: - problemMessage: "The type parameter '{0}' is annotated with @required but only named parameters without a default value can be annotated with it." - correctionMessage: Remove @required. - comment: |- - This hint is generated anywhere where `@required` annotates a named - parameter with a default value. - - Parameters: - 0: the name of the member - INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM: - problemMessage: "Incorrect use of the annotation @required on the optional positional parameter '{0}'. Optional positional parameters cannot be required." - correctionMessage: Remove @required. - comment: |- - This hint is generated anywhere where `@required` annotates an optional - positional parameter. - - Parameters: - 0: the name of the member - INVALID_REQUIRED_POSITIONAL_PARAM: - problemMessage: "Redundant use of the annotation @required on the required positional parameter '{0}'." - correctionMessage: Remove @required. - comment: |- - This hint is generated anywhere where `@required` annotates a non optional - positional parameter. - - Parameters: - 0: the name of the member - RETURN_TYPE_INVALID_FOR_CATCH_ERROR: - sharedName: INVALID_RETURN_TYPE_FOR_CATCH_ERROR - problemMessage: "The return type '{0}' isn't assignable to '{1}', as required by 'Future.catchError'." - hasPublishedDocs: true - comment: |- - Parameters: - 0: the return type of the function - 1: the expected return type as defined by the type of the Future - RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR: - sharedName: INVALID_RETURN_TYPE_FOR_CATCH_ERROR - problemMessage: "A value of type '{0}' can't be returned by the 'onError' handler because it must be assignable to '{1}'." - hasPublishedDocs: true - comment: |- - Parameters: - 0: the return type as declared in the return statement - 1: the expected return type as defined by the type of the Future - documentation: |- - #### Description - - The analyzer produces this diagnostic when an invocation of - `Future.catchError` has an argument whose return type isn't compatible with - the type returned by the instance of `Future`. At runtime, the method - `catchError` attempts to return the value from the callback as the result - of the future, which results in another exception being thrown. - - #### Examples - - The following code produces this diagnostic because `future` is declared to - return an `int` while `callback` is declared to return a `String`, and - `String` isn't a subtype of `int`: - - ```dart - void f(Future future, String Function(dynamic, StackTrace) callback) { - future.catchError([!callback!]); - } - ``` - - The following code produces this diagnostic because the closure being - passed to `catchError` returns an `int` while `future` is declared to - return a `String`: - - ```dart - void f(Future future) { - future.catchError((error, stackTrace) => [!3!]); - } - ``` - - #### Common fixes - - If the instance of `Future` is declared correctly, then change the callback - to match: - - ```dart - void f(Future future, int Function(dynamic, StackTrace) callback) { - future.catchError(callback); - } - ``` - - If the declaration of the instance of `Future` is wrong, then change it to - match the callback: - - ```dart - void f(Future future, String Function(dynamic, StackTrace) callback) { - future.catchError(callback); - } - ``` - INVALID_SEALED_ANNOTATION: - problemMessage: "The annotation '@sealed' can only be applied to classes." - correctionMessage: Try removing the '@sealed' annotation. - hasPublishedDocs: true - comment: |- - This hint is generated anywhere where `@sealed` annotates something other - than a class. - - No parameters. - documentation: |- - #### Description - - The analyzer produces this diagnostic when a declaration other than a - class declaration has the `@sealed` annotation on it. - - #### Example - - The following code produces this diagnostic because the `@sealed` - annotation is on a method declaration: - - ```dart - import 'package:meta/meta.dart'; - - class A { - [!@sealed!] - void m() {} - } - ``` - - #### Common fixes - - Remove the annotation: - - ```dart - class A { - void m() {} - } - ``` INVALID_USE_OF_INTERNAL_MEMBER: problemMessage: "The member '{0}' can only be used within its package." comment: |- @@ -22796,6 +22665,137 @@ WarningCode: comment: |- No parameters. hasPublishedDocs: true + INVALID_REQUIRED_NAMED_PARAM: + problemMessage: "The type parameter '{0}' is annotated with @required but only named parameters without a default value can be annotated with it." + correctionMessage: Remove @required. + comment: |- + This hint is generated anywhere where `@required` annotates a named + parameter with a default value. + + Parameters: + 0: the name of the member + INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM: + problemMessage: "Incorrect use of the annotation @required on the optional positional parameter '{0}'. Optional positional parameters cannot be required." + correctionMessage: Remove @required. + comment: |- + This hint is generated anywhere where `@required` annotates an optional + positional parameter. + + Parameters: + 0: the name of the member + INVALID_REQUIRED_POSITIONAL_PARAM: + problemMessage: "Redundant use of the annotation @required on the required positional parameter '{0}'." + correctionMessage: Remove @required. + comment: |- + This hint is generated anywhere where `@required` annotates a non optional + positional parameter. + + Parameters: + 0: the name of the member + RETURN_TYPE_INVALID_FOR_CATCH_ERROR: + sharedName: INVALID_RETURN_TYPE_FOR_CATCH_ERROR + problemMessage: "The return type '{0}' isn't assignable to '{1}', as required by 'Future.catchError'." + hasPublishedDocs: true + comment: |- + Parameters: + 0: the return type of the function + 1: the expected return type as defined by the type of the Future + RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR: + sharedName: INVALID_RETURN_TYPE_FOR_CATCH_ERROR + problemMessage: "A value of type '{0}' can't be returned by the 'onError' handler because it must be assignable to '{1}'." + hasPublishedDocs: true + comment: |- + Parameters: + 0: the return type as declared in the return statement + 1: the expected return type as defined by the type of the Future + documentation: |- + #### Description + + The analyzer produces this diagnostic when an invocation of + `Future.catchError` has an argument whose return type isn't compatible with + the type returned by the instance of `Future`. At runtime, the method + `catchError` attempts to return the value from the callback as the result + of the future, which results in another exception being thrown. + + #### Examples + + The following code produces this diagnostic because `future` is declared to + return an `int` while `callback` is declared to return a `String`, and + `String` isn't a subtype of `int`: + + ```dart + void f(Future future, String Function(dynamic, StackTrace) callback) { + future.catchError([!callback!]); + } + ``` + + The following code produces this diagnostic because the closure being + passed to `catchError` returns an `int` while `future` is declared to + return a `String`: + + ```dart + void f(Future future) { + future.catchError((error, stackTrace) => [!3!]); + } + ``` + + #### Common fixes + + If the instance of `Future` is declared correctly, then change the callback + to match: + + ```dart + void f(Future future, int Function(dynamic, StackTrace) callback) { + future.catchError(callback); + } + ``` + + If the declaration of the instance of `Future` is wrong, then change it to + match the callback: + + ```dart + void f(Future future, String Function(dynamic, StackTrace) callback) { + future.catchError(callback); + } + ``` + INVALID_SEALED_ANNOTATION: + problemMessage: "The annotation '@sealed' can only be applied to classes." + correctionMessage: Try removing the '@sealed' annotation. + hasPublishedDocs: true + comment: |- + This hint is generated anywhere where `@sealed` annotates something other + than a class. + + No parameters. + documentation: |- + #### Description + + The analyzer produces this diagnostic when a declaration other than a + class declaration has the `@sealed` annotation on it. + + #### Example + + The following code produces this diagnostic because the `@sealed` + annotation is on a method declaration: + + ```dart + import 'package:meta/meta.dart'; + + class A { + [!@sealed!] + void m() {} + } + ``` + + #### Common fixes + + Remove the annotation: + + ```dart + class A { + void m() {} + } + ``` NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR: aliasFor: HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR comment: This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR]. diff --git a/pkg/analyzer/test/src/diagnostics/invalid_required_named_param_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_required_named_param_test.dart index 50c6f22cc8b3..103ec101a365 100644 --- a/pkg/analyzer/test/src/diagnostics/invalid_required_named_param_test.dart +++ b/pkg/analyzer/test/src/diagnostics/invalid_required_named_param_test.dart @@ -27,7 +27,7 @@ import 'package:meta/meta.dart'; m({@required a = 1}) => null; ''', [ - error(HintCode.INVALID_REQUIRED_NAMED_PARAM, 37, 15), + error(WarningCode.INVALID_REQUIRED_NAMED_PARAM, 37, 15), ]); } @@ -37,7 +37,7 @@ import 'package:meta/meta.dart'; m(a, {@required b = 1}) => null; ''', [ - error(HintCode.INVALID_REQUIRED_NAMED_PARAM, 40, 15), + error(WarningCode.INVALID_REQUIRED_NAMED_PARAM, 40, 15), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/invalid_required_optional_positional_param_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_required_optional_positional_param_test.dart index 4af82b823d39..131235f97609 100644 --- a/pkg/analyzer/test/src/diagnostics/invalid_required_optional_positional_param_test.dart +++ b/pkg/analyzer/test/src/diagnostics/invalid_required_optional_positional_param_test.dart @@ -28,7 +28,7 @@ import 'package:meta/meta.dart'; m([@required a]) => null; ''', [ - error(HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 37, 11), + error(WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 37, 11), ]); } @@ -38,7 +38,7 @@ import 'package:meta/meta.dart'; m(a, [@required b]) => null; ''', [ - error(HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 40, 11), + error(WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 40, 11), ]); } @@ -48,7 +48,7 @@ import 'package:meta/meta.dart'; m([@required a = 1]) => null; ''', [ - error(HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 37, 15), + error(WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 37, 15), ]); } @@ -58,7 +58,7 @@ import 'package:meta/meta.dart'; m([a, @required b = 1]) => null; ''', [ - error(HintCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 40, 15), + error(WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM, 40, 15), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/invalid_required_positional_param_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_required_positional_param_test.dart index 072131e4f7df..dbde98a334dc 100644 --- a/pkg/analyzer/test/src/diagnostics/invalid_required_positional_param_test.dart +++ b/pkg/analyzer/test/src/diagnostics/invalid_required_positional_param_test.dart @@ -27,7 +27,7 @@ import 'package:meta/meta.dart'; m(@required a) => null; ''', [ - error(HintCode.INVALID_REQUIRED_POSITIONAL_PARAM, 36, 11), + error(WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM, 36, 11), ]); } @@ -37,7 +37,7 @@ import 'package:meta/meta.dart'; m(a, @required b) => null; ''', [ - error(HintCode.INVALID_REQUIRED_POSITIONAL_PARAM, 39, 11), + error(WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM, 39, 11), ]); } @@ -47,7 +47,7 @@ import 'package:meta/meta.dart'; typedef F = void Function(@required int a); ''', [ - error(HintCode.INVALID_REQUIRED_POSITIONAL_PARAM, 60, 15), + error(WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM, 60, 15), ]); } @@ -57,7 +57,7 @@ import 'package:meta/meta.dart'; typedef F = void Function(@required int); ''', [ - error(HintCode.INVALID_REQUIRED_POSITIONAL_PARAM, 60, 13), + error(WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM, 60, 13), ]); } diff --git a/pkg/analyzer/test/src/diagnostics/invalid_sealed_annotation_test.dart b/pkg/analyzer/test/src/diagnostics/invalid_sealed_annotation_test.dart index 20a4f6258747..32ce0685253a 100644 --- a/pkg/analyzer/test/src/diagnostics/invalid_sealed_annotation_test.dart +++ b/pkg/analyzer/test/src/diagnostics/invalid_sealed_annotation_test.dart @@ -35,7 +35,7 @@ import 'package:meta/meta.dart'; @sealed mixin M {} ''', [ - error(HintCode.INVALID_SEALED_ANNOTATION, 34, 7), + error(WarningCode.INVALID_SEALED_ANNOTATION, 34, 7), ]); } @@ -57,7 +57,7 @@ import 'package:meta/meta.dart'; @sealed m({a = 1}) => null; ''', [ - error(HintCode.INVALID_SEALED_ANNOTATION, 34, 7), + error(WarningCode.INVALID_SEALED_ANNOTATION, 34, 7), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart index c9f2cceb66d0..921dc26dd951 100644 --- a/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_of_invalid_type_from_catch_error_test.dart @@ -36,7 +36,7 @@ void f(Future future) { future.catchError((e, st) => ''); } ''', [ - error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 61, 2), + error(WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 61, 2), ]); } } @@ -116,7 +116,7 @@ void f(Future future) { }); } ''', [ - error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 119, 3), + error(WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 119, 3), ]); } @@ -152,7 +152,7 @@ void f(Future future) { future.catchError((e, st) => 'c'); } ''', [ - error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 60, 3), + error(WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 60, 3), ]); } @@ -186,7 +186,7 @@ void f(Future future, void Function() g) { future.catchError((e, st) => g()); } ''', [ - error(HintCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 79, 3), + error(WarningCode.RETURN_OF_INVALID_TYPE_FROM_CATCH_ERROR, 79, 3), ]); } } diff --git a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart index b5a19e87c718..59d8a7ce0aa4 100644 --- a/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart +++ b/pkg/analyzer/test/src/diagnostics/return_type_invalid_for_catch_error_test.dart @@ -23,7 +23,7 @@ void f(Future future, String? Function(dynamic, StackTrace) cb) { future.catchError(cb); } ''', [ - error(HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 91, 2), + error(WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 91, 2), ]); } } @@ -52,7 +52,7 @@ void f(Future future, String Function(dynamic, StackTrace) cb) { future.catchError(cb); } ''', [ - error(HintCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 90, 2), + error(WarningCode.RETURN_TYPE_INVALID_FOR_CATCH_ERROR, 90, 2), ]); }