Skip to content

Commit 9833cb4

Browse files
srawlinsCommit Queue
authored and
Commit Queue
committed
[analyzer] Move 4 more HintCodes to be WarningCodes, NON_CONST*, NULL_CHECK*, STRICT_RAW_TYPE
Bug: #50796 Change-Id: Idcac3ddb582e5b46263fd017c39402b1c11914d7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289447 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 35b7f2d commit 9833cb4

11 files changed

+211
-217
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,25 +1425,6 @@ HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION:
14251425
HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE:
14261426
status: noFix
14271427
notes: Deprecated
1428-
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR:
1429-
status: needsFix
1430-
notes: |-
1431-
The fix is to add `const` before the constructor invocation.
1432-
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW:
1433-
status: needsFix
1434-
notes: |-
1435-
The fix is to replace `new` with `const`.
1436-
HintCode.NULL_CHECK_ALWAYS_FAILS:
1437-
status: needsFix
1438-
notes: |-
1439-
Remove the null check.
1440-
HintCode.STRICT_RAW_TYPE:
1441-
status: needsFix
1442-
notes: |-
1443-
One fix would be to add an explicit `<dynamic>`, but we can also provide
1444-
more helpful fixes that pretend inference works the way the user may
1445-
have thought it did. For example in: `List a = <int>[];`, we can add
1446-
`<int>` after `List`.
14471428
HintCode.UNIGNORABLE_IGNORE:
14481429
status: needsFix
14491430
notes: |-
@@ -2742,6 +2723,14 @@ WarningCode.MUST_BE_IMMUTABLE:
27422723
status: noFix
27432724
WarningCode.MUST_CALL_SUPER:
27442725
status: hasFix
2726+
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR:
2727+
status: needsFix
2728+
notes: |-
2729+
The fix is to add `const` before the constructor invocation.
2730+
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW:
2731+
status: needsFix
2732+
notes: |-
2733+
The fix is to replace `new` with `const`.
27452734
WarningCode.NULLABLE_TYPE_IN_CATCH_CLAUSE:
27462735
status: hasFix
27472736
WarningCode.NULL_ARGUMENT_TO_NON_NULL_TYPE:
@@ -2753,6 +2742,10 @@ WarningCode.NULL_AWARE_IN_CONDITION:
27532742
status: noFix
27542743
WarningCode.NULL_AWARE_IN_LOGICAL_OPERATOR:
27552744
status: noFix
2745+
WarningCode.NULL_CHECK_ALWAYS_FAILS:
2746+
status: needsFix
2747+
notes: |-
2748+
Remove the null check.
27562749
WarningCode.OVERRIDE_ON_NON_OVERRIDING_FIELD:
27572750
status: hasFix
27582751
WarningCode.OVERRIDE_ON_NON_OVERRIDING_GETTER:
@@ -2808,6 +2801,13 @@ WarningCode.SDK_VERSION_UI_AS_CODE:
28082801
WarningCode.SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT:
28092802
status: noFix
28102803
notes: Deprecated
2804+
WarningCode.STRICT_RAW_TYPE:
2805+
status: needsFix
2806+
notes: |-
2807+
One fix would be to add an explicit `<dynamic>`, but we can also provide
2808+
more helpful fixes that pretend inference works the way the user may
2809+
have thought it did. For example in: `List a = <int>[];`, we can add
2810+
`<int>` after `List`.
28112811
WarningCode.SUBTYPE_OF_SEALED_CLASS:
28122812
status: needsFix
28132813
notes: |-

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -164,55 +164,6 @@ class HintCode extends AnalyzerErrorCode {
164164
hasPublishedDocs: true,
165165
);
166166

167-
/// Generate a hint for non-const instance creation using a constructor
168-
/// annotated with `@literal`.
169-
///
170-
/// Parameters:
171-
/// 0: the name of the class defining the annotated constructor
172-
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR = HintCode(
173-
'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR',
174-
"This instance creation must be 'const', because the {0} constructor is "
175-
"marked as '@literal'.",
176-
correctionMessage: "Try adding a 'const' keyword.",
177-
hasPublishedDocs: true,
178-
);
179-
180-
/// Generate a hint for non-const instance creation (with the `new` keyword)
181-
/// using a constructor annotated with `@literal`.
182-
///
183-
/// Parameters:
184-
/// 0: the name of the class defining the annotated constructor
185-
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW =
186-
HintCode(
187-
'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR',
188-
"This instance creation must be 'const', because the {0} constructor is "
189-
"marked as '@literal'.",
190-
correctionMessage: "Try replacing the 'new' keyword with 'const'.",
191-
hasPublishedDocs: true,
192-
uniqueName: 'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW',
193-
);
194-
195-
/// No parameters.
196-
static const HintCode NULL_CHECK_ALWAYS_FAILS = HintCode(
197-
'NULL_CHECK_ALWAYS_FAILS',
198-
"This null-check will always throw an exception because the expression "
199-
"will always evaluate to 'null'.",
200-
hasPublishedDocs: true,
201-
);
202-
203-
/// When "strict-raw-types" is enabled, "raw types" must have type arguments.
204-
///
205-
/// A "raw type" is a type name that does not use inference to fill in missing
206-
/// type arguments; instead, each type argument is instantiated to its bound.
207-
///
208-
/// Parameters:
209-
/// 0: the name of the generic type
210-
static const HintCode STRICT_RAW_TYPE = HintCode(
211-
'STRICT_RAW_TYPE',
212-
"The generic type '{0}' should have explicit type arguments but doesn't.",
213-
correctionMessage: "Use explicit type arguments for '{0}'.",
214-
);
215-
216167
/// Parameters:
217168
/// 0: the name of the non-diagnostic being ignored
218169
static const HintCode UNIGNORABLE_IGNORE = HintCode(

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
811811
_deprecatedVerifier.postfixExpression(node);
812812
if (node.operator.type == TokenType.BANG &&
813813
node.operand.typeOrThrow.isDartCoreNull) {
814-
_errorReporter.reportErrorForNode(HintCode.NULL_CHECK_ALWAYS_FAILS, node);
814+
_errorReporter.reportErrorForNode(
815+
WarningCode.NULL_CHECK_ALWAYS_FAILS, node);
815816
}
816817
super.visitPostfixExpression(node);
817818
}
@@ -1344,9 +1345,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
13441345
if (constructorName.name != null) {
13451346
fullConstructorName = '$fullConstructorName.${constructorName.name}';
13461347
}
1347-
HintCode hint = node.keyword?.keyword == Keyword.NEW
1348-
? HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW
1349-
: HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
1348+
var hint = node.keyword?.keyword == Keyword.NEW
1349+
? WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW
1350+
: WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
13501351
_errorReporter.reportErrorForNode(hint, node, [fullConstructorName]);
13511352
}
13521353
}

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6453,9 +6453,33 @@ class WarningCode extends AnalyzerErrorCode {
64536453
hasPublishedDocs: true,
64546454
);
64556455

6456-
/// This is the new replacement for [HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR].
6457-
static const HintCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR =
6458-
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR;
6456+
/// Generate a hint for non-const instance creation using a constructor
6457+
/// annotated with `@literal`.
6458+
///
6459+
/// Parameters:
6460+
/// 0: the name of the class defining the annotated constructor
6461+
static const WarningCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR = WarningCode(
6462+
'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR',
6463+
"This instance creation must be 'const', because the {0} constructor is "
6464+
"marked as '@literal'.",
6465+
correctionMessage: "Try adding a 'const' keyword.",
6466+
hasPublishedDocs: true,
6467+
);
6468+
6469+
/// Generate a hint for non-const instance creation (with the `new` keyword)
6470+
/// using a constructor annotated with `@literal`.
6471+
///
6472+
/// Parameters:
6473+
/// 0: the name of the class defining the annotated constructor
6474+
static const WarningCode NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW =
6475+
WarningCode(
6476+
'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR',
6477+
"This instance creation must be 'const', because the {0} constructor is "
6478+
"marked as '@literal'.",
6479+
correctionMessage: "Try replacing the 'new' keyword with 'const'.",
6480+
hasPublishedDocs: true,
6481+
uniqueName: 'NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW',
6482+
);
64596483

64606484
/// No parameters.
64616485
static const WarningCode NULLABLE_TYPE_IN_CATCH_CLAUSE = WarningCode(
@@ -6503,6 +6527,14 @@ class WarningCode extends AnalyzerErrorCode {
65036527
"an operand of a logical operator.",
65046528
);
65056529

6530+
/// No parameters.
6531+
static const WarningCode NULL_CHECK_ALWAYS_FAILS = WarningCode(
6532+
'NULL_CHECK_ALWAYS_FAILS',
6533+
"This null-check will always throw an exception because the expression "
6534+
"will always evaluate to 'null'.",
6535+
hasPublishedDocs: true,
6536+
);
6537+
65066538
/// A field with the override annotation does not override a getter or setter.
65076539
///
65086540
/// No parameters.
@@ -6777,6 +6809,19 @@ class WarningCode extends AnalyzerErrorCode {
67776809
hasPublishedDocs: true,
67786810
);
67796811

6812+
/// When "strict-raw-types" is enabled, "raw types" must have type arguments.
6813+
///
6814+
/// A "raw type" is a type name that does not use inference to fill in missing
6815+
/// type arguments; instead, each type argument is instantiated to its bound.
6816+
///
6817+
/// Parameters:
6818+
/// 0: the name of the generic type
6819+
static const WarningCode STRICT_RAW_TYPE = WarningCode(
6820+
'STRICT_RAW_TYPE',
6821+
"The generic type '{0}' should have explicit type arguments but doesn't.",
6822+
correctionMessage: "Use explicit type arguments for '{0}'.",
6823+
);
6824+
67806825
/// Parameters:
67816826
/// 0: the name of the sealed class
67826827
static const WarningCode SUBTYPE_OF_SEALED_CLASS = WarningCode(

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,6 @@ const List<ErrorCode> errorCodeValues = [
595595
HintCode.DIVISION_OPTIMIZATION,
596596
HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION,
597597
HintCode.IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE,
598-
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR,
599-
HintCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW,
600-
HintCode.NULL_CHECK_ALWAYS_FAILS,
601-
HintCode.STRICT_RAW_TYPE,
602598
HintCode.UNIGNORABLE_IGNORE,
603599
HintCode.UNNECESSARY_CAST,
604600
HintCode.UNNECESSARY_FINAL,
@@ -965,11 +961,14 @@ const List<ErrorCode> errorCodeValues = [
965961
WarningCode.MIXIN_ON_SEALED_CLASS,
966962
WarningCode.MUST_BE_IMMUTABLE,
967963
WarningCode.MUST_CALL_SUPER,
964+
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR,
965+
WarningCode.NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR_USING_NEW,
968966
WarningCode.NULLABLE_TYPE_IN_CATCH_CLAUSE,
969967
WarningCode.NULL_ARGUMENT_TO_NON_NULL_TYPE,
970968
WarningCode.NULL_AWARE_BEFORE_OPERATOR,
971969
WarningCode.NULL_AWARE_IN_CONDITION,
972970
WarningCode.NULL_AWARE_IN_LOGICAL_OPERATOR,
971+
WarningCode.NULL_CHECK_ALWAYS_FAILS,
973972
WarningCode.OVERRIDE_ON_NON_OVERRIDING_FIELD,
974973
WarningCode.OVERRIDE_ON_NON_OVERRIDING_GETTER,
975974
WarningCode.OVERRIDE_ON_NON_OVERRIDING_METHOD,
@@ -994,6 +993,7 @@ const List<ErrorCode> errorCodeValues = [
994993
WarningCode.SDK_VERSION_SINCE,
995994
WarningCode.SDK_VERSION_UI_AS_CODE,
996995
WarningCode.SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT,
996+
WarningCode.STRICT_RAW_TYPE,
997997
WarningCode.SUBTYPE_OF_SEALED_CLASS,
998998
WarningCode.TEXT_DIRECTION_CODE_POINT_IN_COMMENT,
999999
WarningCode.TEXT_DIRECTION_CODE_POINT_IN_LITERAL,

pkg/analyzer/lib/src/error/type_arguments_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class TypeArgumentsVerifier {
308308
// See https://github.com/dart-lang/language/blob/master/resources/type-system/strict-raw-types.md#conditions-for-a-raw-type-hint
309309
} else {
310310
_errorReporter
311-
.reportErrorForNode(HintCode.STRICT_RAW_TYPE, node, [type]);
311+
.reportErrorForNode(WarningCode.STRICT_RAW_TYPE, node, [type]);
312312
}
313313
}
314314
}

0 commit comments

Comments
 (0)