From c86bfe3e2cd079af380e684f654316c11753f6c0 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 19 Aug 2021 22:22:06 +0000 Subject: [PATCH] Correct type of CONSTRUCTOR_TEAROFFS_NOT_ENABLED code Additionally, sort the UNUSED_RESULT_* codes. This addresses comments in https://dart-review.googlesource.com/c/sdk/+/209300 Change-Id: I4d3fd25703f6df59f8ad985352c87406e218b544 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209880 Reviewed-by: Brian Wilkerson Reviewed-by: Konstantin Shcheglov Commit-Queue: Samuel Rawlins --- pkg/analyzer/lib/error/error.dart | 2 +- .../lib/src/dart/error/hint_codes.dart | 87 ++++++++++++------- .../constructor_reference_resolver.dart | 2 +- pkg/analyzer/lib/src/error/codes.dart | 17 ---- .../constructor_reference_test.dart | 2 +- .../language/constructor/reference_test.dart | 4 - .../constructor/reference_test.dart | 4 - 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart index d315c84d422..1b7a17f831d 100644 --- a/pkg/analyzer/lib/error/error.dart +++ b/pkg/analyzer/lib/error/error.dart @@ -141,7 +141,6 @@ const List errorCodeValues = [ CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR, CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT, - CompileTimeErrorCode.CONSTRUCTOR_TEAROFFS_NOT_ENABLED, CompileTimeErrorCode.CONTINUE_LABEL_ON_SWITCH, CompileTimeErrorCode.COULD_NOT_INFER, CompileTimeErrorCode.DEFAULT_LIST_CONSTRUCTOR, @@ -594,6 +593,7 @@ const List errorCodeValues = [ HintCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT, HintCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, HintCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT, + HintCode.SDK_VERSION_CONSTRUCTOR_TEAROFFS, HintCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT, HintCode.SDK_VERSION_EXTENSION_METHODS, HintCode.SDK_VERSION_GT_GT_GT_OPERATOR, diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.dart index afaad1f594a..24533f29fd1 100644 --- a/pkg/analyzer/lib/src/dart/error/hint_codes.dart +++ b/pkg/analyzer/lib/src/dart/error/hint_codes.dart @@ -95,37 +95,6 @@ class HintCode extends AnalyzerErrorCode { "The receiver uses '?.', so its value can be null.", correction: "Replace the '.' with a '?.' in the invocation."); - /** - * Generate a hint for method, property or function annotated with - * `@useResult` whose invocation is unchecked. - * - * Parameters: - * 0: the name of the annotated method, property or function - */ - static const HintCode UNUSED_RESULT = HintCode( - 'UNUSED_RESULT', "'{0}' should be used.", - correction: - "Try using the result by invoking a member, passing it to a function, or returning it from this function.", - hasPublishedDocs: false); - - /** - * Generate a hint for method, property or function annotated with - * `@useResult` whose invocation is unchecked. - * - * Parameters: - * 0: the name of the annotated method, property or function - * 1: message details - */ - static const HintCode UNUSED_RESULT_WITH_MESSAGE = HintCode( - 'UNUSED_RESULT', - "'{0}' should be used. {1}.", - // todo(pq): consider passing in correction details: https://github.com/dart-lang/sdk/issues/46066 - correction: - "Try using the result by invoking a member, passing it to a function, or returning it from this function.", - hasPublishedDocs: false, - uniqueName: 'HintCode.UNUSED_RESULT_WITH_MESSAGE', - ); - /** * Dead code is code that is never reached, this can happen for instance if a * statement follows a return statement. @@ -2244,6 +2213,25 @@ class HintCode extends AnalyzerErrorCode { correction: "Try updating the SDK constraints.", hasPublishedDocs: true); + /** + * A constructor cannot be torn off without the 'constructor-tearoffs' + * language feature. + * + * There is also a [ParserError.EXPERIMENT_NOT_ENABLED] code which catches + * some cases of constructor tearoff features (like `List.filled;`). + * Other constructor tearoff cases are not realized until resolution + * (like `List.filled;`). + */ + static const HintCode SDK_VERSION_CONSTRUCTOR_TEAROFFS = HintCode( + 'SDK_VERSION_CONSTRUCTOR_TEAROFFS', + "Tearing off a constructor requires the 'constructor-tearoffs' " + "language feature.", + // TODO(srawlins): Update this text to something like "Try updating + // your pubspec.yaml to set the minimum SDK constraint to 2.14 or + // higher, and running 'pub get'." + correction: "Try enabling the experiment by including " + "'--enable-experiments=constructor-tearoffs' in the 'dart' command."); + /** * No parameters. */ @@ -3473,6 +3461,43 @@ class HintCode extends AnalyzerErrorCode { correction: "Try removing the variable or using it.", hasPublishedDocs: true); + /** + * The result of invoking a method, property, or function annotated with + * `@useResult` must be used (assigned, passed to a function as an argument, + * or returned by a function). + * + * Parameters: + * 0: the name of the annotated method, property or function + */ + static const HintCode UNUSED_RESULT = HintCode( + 'UNUSED_RESULT', + "'{0}' should be used.", + correction: "Try using the result by invoking a member, passing it to a " + "function, or returning it from this function.", + hasPublishedDocs: false, + ); + + /** + * The result of invoking a method, property, or function annotated with + * `@useResult` must be used (assigned, passed to a function as an argument, + * or returned by a function). + * + * Parameters: + * 0: the name of the annotated method, property or function + * 1: message details + */ + static const HintCode UNUSED_RESULT_WITH_MESSAGE = HintCode( + 'UNUSED_RESULT', + "'{0}' should be used. {1}.", + // todo(pq): consider passing in correction details: + // https://github.com/dart-lang/sdk/issues/46066 + correction: + "Try using the result by invoking a member, passing it to a function, " + "or returning it from this function.", + hasPublishedDocs: false, + uniqueName: 'HintCode.UNUSED_RESULT_WITH_MESSAGE', + ); + /** * Parameters: * 0: the name that is shown but not used diff --git a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart index ce1fd8432a8..ac1868dca99 100644 --- a/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/constructor_reference_resolver.dart @@ -22,7 +22,7 @@ class ConstructorReferenceResolver { // Only report this if [node] has no explicit type arguments; otherwise // the parser has already reported an error. _resolver.errorReporter.reportErrorForNode( - CompileTimeErrorCode.CONSTRUCTOR_TEAROFFS_NOT_ENABLED, node, []); + HintCode.SDK_VERSION_CONSTRUCTOR_TEAROFFS, node, []); } node.constructorName.accept(_resolver); _inferArgumentTypes(node); diff --git a/pkg/analyzer/lib/src/error/codes.dart b/pkg/analyzer/lib/src/error/codes.dart index dce95dcda69..cadf3c78ba1 100644 --- a/pkg/analyzer/lib/src/error/codes.dart +++ b/pkg/analyzer/lib/src/error/codes.dart @@ -2262,23 +2262,6 @@ class CompileTimeErrorCode extends AnalyzerErrorCode { "Evaluation of this constant expression throws an " "IntegerDivisionByZeroException."); - /** - * A constructor cannot be torn off without the 'constructor-tearoffs' - * language feature. - * - * There is also a [ParserError.EXPERIMENT_NOT_ENABLED] code which catches - * some cases of constructor tearoff features (like `List.filled;`). - * Other constructor tearoff cases are not realized until resolution - * (like `List.filled;`). - */ - static const CompileTimeErrorCode CONSTRUCTOR_TEAROFFS_NOT_ENABLED = - CompileTimeErrorCode( - 'CONSTRUCTOR_TEAROFFS_NOT_ENABLED', - "Tearing off a constructor requires the 'constructor-tearoffs' " - "language feature.", - correction: "Try updating your pubspec.yaml to set the minimum SDK " - "constraint to 2.14 or higher, and running 'pub get'."); - /** * 16.12.2 Const: An expression of one of the forms !e, e1 && e2 or e1 || e2, * where e, e1 and e2 are constant expressions that evaluate to a boolean diff --git a/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart b/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart index 0c94b3ccddb..21b86f7ab2a 100644 --- a/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/constructor_reference_test.dart @@ -584,7 +584,7 @@ void bar() { A.foo; } ''', [ - error(CompileTimeErrorCode.CONSTRUCTOR_TEAROFFS_NOT_ENABLED, 39, 5), + error(HintCode.SDK_VERSION_CONSTRUCTOR_TEAROFFS, 39, 5), ]); var classElement = findElement.class_('A'); diff --git a/tests/language/constructor/reference_test.dart b/tests/language/constructor/reference_test.dart index 36ca27d047a..37558808bf1 100644 --- a/tests/language/constructor/reference_test.dart +++ b/tests/language/constructor/reference_test.dart @@ -88,8 +88,6 @@ main() { Foo.bar.baz(); // ^^^ // [cfe] Getter not found: 'bar'. -//^^^^^^^ -// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED // ^^^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD Foo(); @@ -117,8 +115,6 @@ main() { Foo.bar.baz(); // ^^^ // [cfe] Getter not found: 'bar'. -//^^^^^^^ -// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED // ^^^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD } diff --git a/tests/language_2/constructor/reference_test.dart b/tests/language_2/constructor/reference_test.dart index 6dff1ad5c68..03d4c5609ce 100644 --- a/tests/language_2/constructor/reference_test.dart +++ b/tests/language_2/constructor/reference_test.dart @@ -90,8 +90,6 @@ main() { Foo.bar.baz(); // ^^^ // [cfe] Getter not found: 'bar'. -//^^^^^^^ -// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED // ^^^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD Foo(); @@ -119,8 +117,6 @@ main() { Foo.bar.baz(); // ^^^ // [cfe] Getter not found: 'bar'. -//^^^^^^^ -// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED // ^^^ // [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD }