Skip to content

Commit 1a7bbce

Browse files
munificentCommit Queue
authored andcommitted
[private named parameters] Allow non-reserved word public names.
To use a private named parameter, the corresponding public name must be a valid identifier. One way it could be invalid is by being a reserved word, as in: ```dart class C({final String _if}); // Error. ``` However, other special identifiers that are not actually reserved words are allowed: ```dart class C({final String _async}); // OK. ``` This fixes that. Change-Id: I6755a613910ae97e7db9b6a7f70e1cf0dd379b17 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465740 Auto-Submit: Bob Nystrom <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 73d463c commit 1a7bbce

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/_fe_analyzer_shared/lib/src/scanner/token_impl.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import 'characters.dart';
1010

1111
import 'token.dart'
1212
show
13+
CommentToken,
1314
DocumentationCommentToken,
15+
Keyword,
16+
KeywordStyle,
17+
LanguageVersionToken,
1418
SimpleToken,
15-
TokenType,
16-
CommentToken,
1719
StringToken,
18-
LanguageVersionToken,
19-
Keyword;
20+
TokenType;
2021

2122
import 'token_constants.dart' show IDENTIFIER_TOKEN;
2223

@@ -375,9 +376,13 @@ String? correspondingPublicName(String identifier) {
375376
// digit.
376377
if (isDigit(firstCharacter)) return null;
377378

378-
// The resulting name must not be a reserved word.
379+
// The resulting name must not be a reserved word (but other kinds of special
380+
// identifiers are allowed).
379381
String publicName = identifier.substring(1);
380-
if (Keyword.keywords.containsKey(publicName)) return null;
382+
if (Keyword.keywords[publicName] case var keyword?
383+
when keyword.keywordStyle == KeywordStyle.reserved) {
384+
return null;
385+
}
381386

382387
return publicName;
383388
}

0 commit comments

Comments
 (0)