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>
This commit is contained in:
pq 2024-01-29 21:04:28 +00:00 committed by Commit Queue
parent 0a0e9fb713
commit 23aff1c23e
9 changed files with 44 additions and 27 deletions

View file

@ -1380,6 +1380,8 @@ CompileTimeErrorCode.PRIVATE_SETTER:
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 @@ WarningCode.RECEIVER_OF_TYPE_NEVER:
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:

View file

@ -1102,6 +1102,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
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 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
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,
],

View file

@ -145,7 +145,7 @@ class AssignmentExpressionResolver {
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,
[],
);

View file

@ -4415,6 +4415,15 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
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 @@ class WarningCode extends AnalyzerErrorCode {
"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:

View file

@ -454,6 +454,7 @@ const List<ErrorCode> errorCodeValues = [
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 @@ const List<ErrorCode> errorCodeValues = [
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,

View file

@ -350,7 +350,8 @@ class ReturnTypeVerifier {
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,
[],
);

View file

@ -95,7 +95,8 @@ mixin ErrorDetectionHelpers {
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,
[],
);

View file

@ -1987,6 +1987,10 @@ CompileTimeErrorCode:
}
}
```
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 @@ WarningCode:
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.

View file

@ -42,7 +42,10 @@ void f((int,) i) {
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 @@ void f((int,) r) {
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 @@ void f((int,) r) {
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 @@ void f((int,) r) {
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 @@ void f((int,) r) {
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),
]);
}