Skip to content

Commit 4a0a36e

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer/front_end] Remove support for messages without parameter names.
Now that the messages in `pkg/front_end/messages.yaml` include `parameters:` entries, support is no longer needed for messages without them. Removing support ensures that we don't accidentally forget to add `parameters:` entries in the future. Additionally, the script `pkg/front_end/tool/add_parameters_to_messages.dart` (which added the `parameters:` entries) is no longer needed. Change-Id: I6a6a696454e6b1b805d48e2db1cd56d67f2dd7f0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448235 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 1c85b0e commit 4a0a36e

File tree

5 files changed

+24
-145
lines changed

5 files changed

+24
-145
lines changed

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,7 @@ class AnalyzerErrorCodeInfo extends ErrorCodeInfo {
304304
}
305305
}
306306

307-
AnalyzerErrorCodeInfo._fromYaml(super.yaml) : super.fromYaml() {
308-
_check();
309-
}
310-
311-
void _check() {
312-
if (parameters == null) throw StateError('Missing `parameters` entry.');
313-
}
307+
AnalyzerErrorCodeInfo._fromYaml(super.yaml) : super.fromYaml();
314308
}
315309

316310
/// Data tables mapping between CFE errors and their corresponding automatically

pkg/analyzer_utilities/lib/messages.dart

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ abstract class ErrorCodeInfo {
299299

300300
/// A list of [ErrorCodeParameter] objects describing the parameters for this
301301
/// error code, obtained from the `parameters` entry in the yaml file.
302-
///
303-
/// If `null`, then there is no `parameters` entry, meaning the error code
304-
/// hasn't been translated from the old placeholder format yet.
305-
final List<ErrorCodeParameter>? parameters;
302+
final List<ErrorCodeParameter> parameters;
306303

307304
/// The raw YAML node that this `ErrorCodeInfo` was parsed from, or `null` if
308305
/// this `ErrorCodeInfo` was created without reference to a raw YAML node.
@@ -322,7 +319,7 @@ abstract class ErrorCodeInfo {
322319
this.deprecatedMessage,
323320
this.previousName,
324321
this.removedIn,
325-
this.parameters,
322+
required this.parameters,
326323
this.yamlNode,
327324
}) {
328325
for (var MapEntry(:key, :value) in {
@@ -364,33 +361,12 @@ abstract class ErrorCodeInfo {
364361
/// Given a messages.yaml entry, come up with a mapping from placeholder
365362
/// patterns in its message strings to their corresponding indices.
366363
Map<String, int> computePlaceholderToIndexMap() {
367-
if (parameters case var parameters?) {
368-
// Parameters were explicitly specified, so the mapping is determined by
369-
// the order in which they were specified.
370-
return {
371-
for (var (index, parameter) in parameters.indexed)
372-
'#${parameter.name}': index,
373-
};
374-
} else {
375-
// Parameters are not explicitly specified, so it's necessary to invent a
376-
// mapping by searching the problemMessage and correctionMessage for
377-
// placeholders.
378-
var mapping = <String, int>{};
379-
for (var value in [problemMessage, correctionMessage]) {
380-
if (value is! String) continue;
381-
for (Match match in placeholderPattern.allMatches(value)) {
382-
// CFE supports a bunch of formatting options that analyzer doesn't;
383-
// make sure none of those are used.
384-
if (match.group(0) != '#${match.group(1)}') {
385-
throw 'Template string ${json.encode(value)} contains unsupported '
386-
'placeholder pattern ${json.encode(match.group(0))}';
387-
}
388-
389-
mapping[match.group(0)!] ??= mapping.length;
390-
}
391-
}
392-
return mapping;
393-
}
364+
// Parameters are always explicitly specified, so the mapping is determined
365+
// by the order in which they were specified.
366+
return {
367+
for (var (index, parameter) in parameters.indexed)
368+
'#${parameter.name}': index,
369+
};
394370
}
395371

396372
void outputConstantHeader(StringSink out) {
@@ -420,13 +396,12 @@ abstract class ErrorCodeInfo {
420396
String className;
421397
String templateParameters = '';
422398
String? withArgumentsName;
423-
if (parameters != null && parameters.isNotEmpty && !usesParameters) {
399+
if (parameters.isNotEmpty && !usesParameters) {
424400
throw StateError(
425401
'Error code declares parameters using a `parameters` entry, but '
426402
"doesn't use them",
427403
);
428-
} else if (parameters == null ||
429-
parameters.any((p) => !p.type.isSupportedByAnalyzer)) {
404+
} else if (parameters.any((p) => !p.type.isSupportedByAnalyzer)) {
430405
// Do not generate literate API yet.
431406
className = errorClassInfo.name;
432407
} else if (parameters.isNotEmpty) {
@@ -520,7 +495,7 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
520495
case []:
521496
if (commentLines.isNotEmpty) commentLines.add('');
522497
commentLines.add('No parameters.');
523-
case var parameters?:
498+
default:
524499
if (commentLines.isNotEmpty) commentLines.add('');
525500
commentLines.add('Parameters:');
526501
for (var p in parameters) {
@@ -559,14 +534,10 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
559534
};
560535

561536
String _computeExpectedTypes() {
562-
if (parameters case var parameters?) {
563-
var expectedTypes = [
564-
for (var parameter in parameters) 'ExpectedType.${parameter.type.name}',
565-
];
566-
return '[${expectedTypes.join(', ')}]';
567-
} else {
568-
return 'null';
569-
}
537+
var expectedTypes = [
538+
for (var parameter in parameters) 'ExpectedType.${parameter.type.name}',
539+
];
540+
return '[${expectedTypes.join(', ')}]';
570541
}
571542

572543
String _encodeString(String s) {
@@ -590,8 +561,10 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
590561
}
591562
}
592563

593-
static List<ErrorCodeParameter>? _decodeParameters(Object? yaml) {
594-
if (yaml == null) return null;
564+
static List<ErrorCodeParameter> _decodeParameters(Object? yaml) {
565+
if (yaml == null) {
566+
throw StateError('Missing parameters section');
567+
}
595568
if (yaml == 'none') return const [];
596569
yaml as Map<Object?, Object?>;
597570
var result = <ErrorCodeParameter>[];

pkg/front_end/messages.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,12 @@
134134
# `#num1%N.M`, `#num2%N.M`, `#num3%N.M`: numbers (doubles) formatted to minimum
135135
# width N and with M fraction digits.
136136
#
137-
# A message declaration may optionally include a map called
138-
# `parameters`; each map key is of the form `TYPE NAME`, and each map
139-
# value is a comment describing the parameter.
137+
# If a diagnostic takes parameters, its declaration must include a map
138+
# called `parameters`; each map key is of the form `TYPE NAME`, and
139+
# each map value is a comment describing the parameter.
140140
#
141-
# If a diagnostic takes no parameters, it should have an entry of the
141+
# If a diagnostic takes no parameters, it must have an entry of the
142142
# form `parameters: none`.
143-
#
144-
# In the future, the `parameters` entry will be required.
145143

146144
AsciiControlCharacter:
147145
parameters:

pkg/front_end/pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ dependencies:
2323
# Use 'any' constraints here; we get our versions from the DEPS file.
2424
dev_dependencies:
2525
analyzer: any
26-
analyzer_plugin: any
2726
analyzer_utilities: any
2827
args: any
2928
build_integration: any
30-
collection: any
3129
compiler: any
3230
dart_style: any
3331
dart2wasm: any

pkg/front_end/tool/add_parameters_to_messages.dart

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)