Skip to content

Commit 2586291

Browse files
stereotype441Commit Queue
authored andcommitted
[front end] Use code... instead of template....
This is part of a series of CLs that will standardize CFE error reporting to always use `codeFoo.withArguments(...)` when reporting errors that take arguments and `codeFoo` when reporting errors that don't take arguments, rather than `templateFoo.withArguments(...)` when reporting errors that take arguments and `messageFoo` when reporting errors that don't take arguments. This change will have two advantages: - It will lend greater consistency to the CFE codebase, by allowing the same `code...` objects to be used both to name error codes (e.g., in test expectations) and to report errors. This will allow everything associated with a certain error code to be found using a single invocation of "Find References" in the editor, rather than having to search separately for uses of the code and the message or template. - It should hopefully make the experience of writing code that reports errors more pleasant, since it will no longer be necessary to look up an error to see whether it takes arguments before using it; instead, the developer will be able to type the name of the message `code...` declaration, and then use autocompletion to see whether `.withArguments(...)` is required. In this CL, the references to the `template...` declarations that define errors are changed to the equivalent `code...` declarations. There is no functional change, since these declarations denote the same constant object. In follow-up CLs, the `template...` declarations will be removed, and then a similar set of changes will be made to replace references to `message...` declarations with references to the corresponding `code...` declaration. Tested: normal trybots Change-Id: I178bd2072349088f342bc39cfc789bcb5c7ef19e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442732 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]> Reviewed-by: Derek Xu <[email protected]>
1 parent bd1eb97 commit 2586291

File tree

90 files changed

+1253
-1426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1253
-1426
lines changed

pkg/_fe_analyzer_shared/lib/src/experiments/errors.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import 'flags.dart';
99
/// enabled.
1010
Message getExperimentNotEnabledMessage(ExperimentalFlag experimentalFlag) {
1111
if (experimentalFlag.isEnabledByDefault) {
12-
return templateExperimentNotEnabled.withArguments(
12+
return codeExperimentNotEnabled.withArguments(
1313
experimentalFlag.name,
1414
experimentalFlag.experimentEnabledVersion.toText(),
1515
);
1616
} else {
17-
return templateExperimentNotEnabledOffByDefault.withArguments(
17+
return codeExperimentNotEnabledOffByDefault.withArguments(
1818
experimentalFlag.name,
1919
);
2020
}

pkg/_fe_analyzer_shared/lib/src/parser/block_kind.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BlockKind {
2727
);
2828
static const BlockKind enumDeclaration = const BlockKind._(
2929
'enum declaration',
30-
template: codes.templateExpectedEnumBody,
30+
template: codes.codeExpectedEnumBody,
3131
);
3232
static const BlockKind extensionDeclaration = const BlockKind._(
3333
'extension declaration',
@@ -43,7 +43,7 @@ class BlockKind {
4343
);
4444
static const BlockKind functionBody = const BlockKind._(
4545
'function body',
46-
template: codes.templateExpectedFunctionBody,
46+
template: codes.codeExpectedFunctionBody,
4747
);
4848
static const BlockKind invalid = const BlockKind._('invalid');
4949
static const BlockKind mixinDeclaration = const BlockKind._(

pkg/_fe_analyzer_shared/lib/src/parser/identifier_context.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import '../messages/codes.dart'
6-
show Message, Template, templateExpectedIdentifier;
5+
import '../messages/codes.dart' show Message, Template, codeExpectedIdentifier;
76

87
import '../scanner/token.dart'
98
show Keyword, Token, TokenIsAExtension, TokenType;
@@ -301,7 +300,7 @@ abstract class IdentifierContext {
301300
this.isScopeReference = false,
302301
this.isBuiltInIdentifierAllowed = true,
303302
bool? allowedInConstantExpression,
304-
this.recoveryTemplate = templateExpectedIdentifier,
303+
this.recoveryTemplate = codeExpectedIdentifier,
305304
}) : this.allowedInConstantExpression =
306305
// Generally, declarations are legal in constant expressions. A
307306
// continuation doesn't affect constant expressions: if what it's

0 commit comments

Comments
 (0)