[messages] Disambiguate recordLiteralOnePositionalNoTrailingCommaByType.
Renames the diagnostic code
`CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma` to
`CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType`. This
avoids an ambiguity between this message and
`ParserErrorCode.recordLiteralOnePositionalNoTrailingComma`.
The two messages need to stay distinct, because one is reported during
parsing, and the other is reported during type analysis. Only
`ParserErrorCode.recordLiteralOnePositionalNoTrailingComma` should
prevent the formatter from running.
Avoiding ambiguities like these is important, because in many cases
the user only sees the diagnostic name; they don't see the class it's
in. For example, `ignore:` comments just give the diagnostic name, and
the web page https://dart.dev/tools/diagnostics only shows diagnostic
names.
In the future I intend to add an error check to the analyzer
diagnostic code generator, to ensure that there are no ambiguities
like these. This CL is a prerequisite for adding the error check.
Note that the `sharedName` of the renamed diagnostic remains
`RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA`, so there will be no
change in how the error is presented to the user.
Change-Id: I6a6a6964c1d4e28c6db71072252abf95fbc13206
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455562
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@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 6f9afd5..2608902 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
@@ -1386,7 +1386,7 @@
status: noFix
CompileTimeErrorCode.READ_POTENTIALLY_UNASSIGNED_FINAL:
status: noFix
-CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
+CompileTimeErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA_BY_TYPE:
status: hasFix
CompileTimeErrorCode.RECURSIVE_CONSTANT_CONSTRUCTOR:
status: noFix
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 d87c27f..87b405e 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -847,7 +847,7 @@
CompileTimeErrorCode.obsoleteColonForDefaultValue: [
ReplaceColonWithEquals.new,
],
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma: [
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType: [
AddTrailingComma.new,
],
CompileTimeErrorCode.returnOfInvalidTypeFromClosure: [
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 5108e81..f5d78f1 100644
--- a/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/assignment_expression_resolver.dart
@@ -150,7 +150,7 @@
)) {
_diagnosticReporter.atNode(
right,
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
);
return;
}
diff --git a/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart
index 76e3555..5e5e7c6 100644
--- a/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart
+++ b/pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart
@@ -466,7 +466,7 @@
CompileTimeErrorCode.privateOptionalParameter,
CompileTimeErrorCode.privateSetter,
CompileTimeErrorCode.readPotentiallyUnassignedFinal,
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
CompileTimeErrorCode.recursiveCompileTimeConstant,
CompileTimeErrorCode.recursiveConstantConstructor,
CompileTimeErrorCode.recursiveConstructorRedirect,
diff --git a/pkg/analyzer/lib/src/error/codes.g.dart b/pkg/analyzer/lib/src/error/codes.g.dart
index 13eb6aa..167cf0e 100644
--- a/pkg/analyzer/lib/src/error/codes.g.dart
+++ b/pkg/analyzer/lib/src/error/codes.g.dart
@@ -6105,18 +6105,23 @@
expectedTypes: [ExpectedType.string],
);
- /// The documentation is in `front_end/message.yaml`.
+ /// This is similar to
+ /// ParserErrorCode.recordLiteralOnePositionalNoTrailingComma, but
+ /// it is reported at type analysis time, based on a type
+ /// incompatibility, rather than at parse time.
///
/// No parameters.
static const CompileTimeErrorWithoutArguments
- recordLiteralOnePositionalNoTrailingComma = CompileTimeErrorWithoutArguments(
- '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,
- expectedTypes: [],
- );
+ recordLiteralOnePositionalNoTrailingCommaByType =
+ CompileTimeErrorWithoutArguments(
+ '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,
+ uniqueName: 'RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA_BY_TYPE',
+ expectedTypes: [],
+ );
/// No parameters.
static const CompileTimeErrorWithoutArguments recursiveCompileTimeConstant =
diff --git a/pkg/analyzer/lib/src/error/return_type_verifier.dart b/pkg/analyzer/lib/src/error/return_type_verifier.dart
index 6d72301..db4fb42 100644
--- a/pkg/analyzer/lib/src/error/return_type_verifier.dart
+++ b/pkg/analyzer/lib/src/error/return_type_verifier.dart
@@ -223,7 +223,8 @@
)) {
_diagnosticReporter.atNode(
expression,
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode
+ .recordLiteralOnePositionalNoTrailingCommaByType,
);
return;
}
diff --git a/pkg/analyzer/lib/src/generated/error_detection_helpers.dart b/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
index 4becc30..4ec33c7 100644
--- a/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
+++ b/pkg/analyzer/lib/src/generated/error_detection_helpers.dart
@@ -138,7 +138,8 @@
)) {
diagnosticReporter.atNode(
expression,
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode
+ .recordLiteralOnePositionalNoTrailingCommaByType,
);
return;
}
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 1c8c846..490dcb8 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -2113,12 +2113,17 @@
}
}
```
- RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
+ RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA_BY_TYPE:
parameters: none
+ sharedName: 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
- comment: The documentation is in `front_end/message.yaml`.
+ comment: |-
+ This is similar to
+ ParserErrorCode.recordLiteralOnePositionalNoTrailingComma, but
+ it is reported at type analysis time, based on a type
+ incompatibility, rather than at parse time.
SET_ELEMENT_FROM_DEFERRED_LIBRARY:
parameters: none
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
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 7e6d068..7bc23df 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
@@ -47,7 +47,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
23,
3,
),
@@ -94,7 +94,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
25,
3,
),
@@ -117,7 +117,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
11,
3,
),
@@ -160,7 +160,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
22,
3,
),
@@ -193,7 +193,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
14,
3,
),
diff --git a/pkg/linter/test/rules/unnecessary_parenthesis_test.dart b/pkg/linter/test/rules/unnecessary_parenthesis_test.dart
index 25134ec..9704468 100644
--- a/pkg/linter/test/rules/unnecessary_parenthesis_test.dart
+++ b/pkg/linter/test/rules/unnecessary_parenthesis_test.dart
@@ -908,7 +908,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
24,
3,
),
@@ -927,7 +927,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
18,
3,
),
@@ -947,7 +947,7 @@
''',
[
error(
- CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingComma,
+ CompileTimeErrorCode.recordLiteralOnePositionalNoTrailingCommaByType,
15,
3,
),