mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
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 <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
643d68793a
commit
c86bfe3e2c
|
@ -141,7 +141,6 @@ const List<ErrorCode> 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<ErrorCode> 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,
|
||||
|
|
|
@ -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<int>.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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<int>.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
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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<int>();
|
||||
|
@ -117,8 +115,6 @@ main() {
|
|||
Foo.bar.baz<int>();
|
||||
// ^^^
|
||||
// [cfe] Getter not found: 'bar'.
|
||||
//^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
|
||||
}
|
||||
|
|
|
@ -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<int>();
|
||||
|
@ -119,8 +117,6 @@ main() {
|
|||
Foo.bar.baz<int>();
|
||||
// ^^^
|
||||
// [cfe] Getter not found: 'bar'.
|
||||
//^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONSTRUCTOR_TEAROFFS_NOT_ENABLED
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue