make `RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA` an error
Fixes: https://github.com/dart-lang/sdk/issues/54760
My thinking is this doesn't qualify as a breaking change in practical terms but would love Sam's feedback.
Change-Id: I073c478b21377113b3bdbdb3f940ef4dd2bea1d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349080
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
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 5cefbeb..2a695ba 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
@@ -1380,6 +1380,8 @@
status: noFix
CompileTimeErrorCode.READ_POTENTIALLY_UNASSIGNED_FINAL:
status: noFix
+CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
+ status: hasFix
CompileTimeErrorCode.RECURSIVE_CONSTANT_CONSTRUCTOR:
status: noFix
CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT:
@@ -3749,8 +3751,6 @@
status: needsFix
notes: |-
We _could_ remove the thing being received (method invocation, etc.)
-WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
- status: hasFix
WarningCode.REDECLARE_ON_NON_REDECLARING_MEMBER:
status: hasFix
WarningCode.REMOVED_LINT_USE:
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 882cd39..1c3dd56 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -1102,6 +1102,9 @@
CompileTimeErrorCode.OBSOLETE_COLON_FOR_DEFAULT_VALUE: [
ReplaceColonWithEquals.new
],
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA: [
+ AddTrailingComma.new,
+ ],
CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION: [
MakeReturnTypeNullable.new,
ReplaceReturnType.new,
@@ -1458,9 +1461,6 @@
WarningCode.OVERRIDE_ON_NON_OVERRIDING_SETTER: [
RemoveAnnotation.new,
],
- WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA: [
- AddTrailingComma.new,
- ],
WarningCode.REDECLARE_ON_NON_REDECLARING_MEMBER: [
RemoveAnnotation.new,
],
diff --git a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
index aa43a9d..89f0769 100644
--- a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
@@ -145,7 +145,7 @@
if (_typeSystem.isAssignableTo(field.type, rightType,
strictCasts: strictCasts)) {
_errorReporter.reportErrorForNode(
- WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
right,
[],
);
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index f984fe4..5ee5511 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -4415,6 +4415,15 @@
hasPublishedDocs: true,
);
+ static const CompileTimeErrorCode
+ RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA = CompileTimeErrorCode(
+ 'RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA',
+ "A record literal with exactly one positional field requires a trailing "
+ "comma.",
+ correctionMessage: "Try adding a trailing comma.",
+ hasPublishedDocs: true,
+ );
+
/// No parameters.
static const CompileTimeErrorCode RECURSIVE_COMPILE_TIME_CONSTANT =
CompileTimeErrorCode(
@@ -7030,15 +7039,6 @@
"Try checking for throw expressions or type errors in the receiver",
);
- static const WarningCode RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA =
- WarningCode(
- 'RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA',
- "A record literal with exactly one positional field requires a trailing "
- "comma.",
- correctionMessage: "Try adding a trailing comma.",
- hasPublishedDocs: true,
- );
-
/// An error code indicating the use of a redeclare annotation on a member that does not redeclare.
///
/// Parameters:
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 883a4d7..d73b1ff 100644
--- a/pkg/analyzer/lib/src/error/error_code_values.g.dart
+++ b/pkg/analyzer/lib/src/error/error_code_values.g.dart
@@ -454,6 +454,7 @@
CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER,
CompileTimeErrorCode.PRIVATE_SETTER,
CompileTimeErrorCode.READ_POTENTIALLY_UNASSIGNED_FINAL,
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
CompileTimeErrorCode.RECURSIVE_CONSTANT_CONSTRUCTOR,
CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT,
@@ -1056,7 +1057,6 @@
WarningCode.OVERRIDE_ON_NON_OVERRIDING_SETTER,
WarningCode.PATTERN_NEVER_MATCHES_VALUE_TYPE,
WarningCode.RECEIVER_OF_TYPE_NEVER,
- WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
WarningCode.REDECLARE_ON_NON_REDECLARING_MEMBER,
WarningCode.REMOVED_LINT_USE,
WarningCode.REPLACED_LINT_USE,
diff --git a/pkg/analyzer/lib/src/error/return_type_verifier.dart b/pkg/analyzer/lib/src/error/return_type_verifier.dart
index d54e70b..af6d9c6 100644
--- a/pkg/analyzer/lib/src/error/return_type_verifier.dart
+++ b/pkg/analyzer/lib/src/error/return_type_verifier.dart
@@ -350,7 +350,8 @@
if (_typeSystem.isAssignableTo(field.type, S,
strictCasts: _strictCasts)) {
_errorReporter.reportErrorForNode(
- WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ CompileTimeErrorCode
+ .RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
expression,
[],
);
diff --git a/pkg/analyzer/lib/src/generated/error_detection_helpers.dart b/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
index 394dabe..a148862 100644
--- a/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
+++ b/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
@@ -95,7 +95,8 @@
if (typeSystem.isAssignableTo(field.type, actualStaticType,
strictCasts: strictCasts)) {
errorReporter.reportErrorForNode(
- WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ CompileTimeErrorCode
+ .RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
expression,
[],
);
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 658cc74..eec2c75 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -1987,6 +1987,10 @@
}
}
```
+ RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
+ problemMessage: "A record literal with exactly one positional field requires a trailing comma."
+ correctionMessage: Try adding a trailing comma.
+ hasPublishedDocs: true
SET_ELEMENT_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as values in a 'const' set literal."
@@ -25248,10 +25252,6 @@
the call are unreachable.
Parameters: none
- RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
- problemMessage: "A record literal with exactly one positional field requires a trailing comma."
- correctionMessage: Try adding a trailing comma.
- hasPublishedDocs: true
REDECLARE_ON_NON_REDECLARING_MEMBER:
problemMessage: "The {0} doesn't redeclare a {0} declared in a superinterface."
correctionMessage: Try updating this member to match a declaration in a superinterface, or removing the redeclare annotation.
diff --git a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart
index 3b1c3fa..1375798 100644
--- a/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/record_literal_one_positional_no_trailing_comma_test.dart
@@ -42,7 +42,10 @@
f((1));
}
''', [
- error(WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA, 23, 3),
+ error(
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ 23,
+ 3),
]);
}
@@ -80,7 +83,10 @@
r = (1);
}
''', [
- error(WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA, 25, 3),
+ error(
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ 25,
+ 3),
]);
}
@@ -96,7 +102,10 @@
await assertErrorsInCode('''
(int,) r = (1);
''', [
- error(WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA, 11, 3),
+ error(
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ 11,
+ 3),
]);
}
@@ -130,7 +139,10 @@
return (1);
}
''', [
- error(WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA, 22, 3),
+ error(
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ 22,
+ 3),
]);
}
@@ -154,7 +166,10 @@
await assertErrorsInCode('''
(int,) f() => (1);
''', [
- error(WarningCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA, 14, 3),
+ error(
+ CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA,
+ 14,
+ 3),
]);
}