Skip to content

Commit 6b89f1e

Browse files
committed
[NFC] Parse: Contextualize accessor introducer.
To the routine that parses the introducer for an accessor whether it is would be first accessor, pass whether it would be the first accessor; from it, return whether the accessor is from an unavailable feature. These both enable expected behavior when an experimental feature is disabled: the former enables maintaining source compatibility with code that uses the introducer name as a function name which is called with a trailing closure as the first expression in an implicit getter. The latter enables suppressing duplicative diagnostics.
1 parent ecba5db commit 6b89f1e

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7904,8 +7904,9 @@ struct Parser::ParsedAccessors {
79047904

79057905
static ParserStatus parseAccessorIntroducer(Parser &P,
79067906
DeclAttributes &Attributes,
7907-
AccessorKind &Kind,
7908-
SourceLoc &Loc) {
7907+
AccessorKind &Kind, SourceLoc &Loc,
7908+
bool isFirstAccessor,
7909+
bool *featureUnavailable) {
79097910
ParserStatus Status;
79107911
assert(Attributes.isEmpty());
79117912
auto AttributeStatus = P.parseDeclAttributeList(Attributes);
@@ -8144,8 +8145,9 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81448145
DeclAttributes Attributes;
81458146
AccessorKind Kind = AccessorKind::Get;
81468147
SourceLoc Loc;
8147-
ParserStatus AccessorStatus =
8148-
parseAccessorIntroducer(*this, Attributes, Kind, Loc);
8148+
bool featureUnavailable = false;
8149+
ParserStatus AccessorStatus = parseAccessorIntroducer(
8150+
*this, Attributes, Kind, Loc, IsFirstAccessor, &featureUnavailable);
81498151
Status |= AccessorStatus;
81508152
if (AccessorStatus.isError() && !AccessorStatus.hasCodeCompletion()) {
81518153
if (Tok.is(tok::code_complete)) {
@@ -8172,7 +8174,9 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81728174

81738175
// Cannot have an implicit getter after other accessor.
81748176
if (!IsFirstAccessor) {
8175-
diagnose(Tok, diag::expected_accessor_kw);
8177+
if (!featureUnavailable) {
8178+
diagnose(Tok, diag::expected_accessor_kw);
8179+
}
81768180
skipUntil(tok::r_brace);
81778181
// Don't signal an error since we recovered.
81788182
break;
@@ -8246,18 +8250,23 @@ void Parser::parseTopLevelAccessors(
82468250
ParserStatus status;
82478251
bool hasEffectfulGet = false;
82488252
bool parsingLimitedSyntax = false;
8253+
bool IsFirstAccessor = true;
82498254
while (!Tok.isAny(tok::r_brace, tok::eof)) {
82508255
DeclAttributes attributes;
82518256
AccessorKind kind = AccessorKind::Get;
82528257
SourceLoc loc;
82538258
ParserStatus accessorStatus =
8254-
parseAccessorIntroducer(*this, attributes, kind, loc);
8259+
parseAccessorIntroducer(*this, attributes, kind, loc, IsFirstAccessor,
8260+
/*featureUnavailable=*/nullptr);
82558261
if (accessorStatus.isError())
82568262
break;
82578263

82588264
(void)parseAccessorAfterIntroducer(loc, kind, accessors, hasEffectfulGet,
82598265
parsingLimitedSyntax, attributes,
82608266
PD_Default, storage, status);
8267+
if (IsFirstAccessor) {
8268+
IsFirstAccessor = false;
8269+
}
82618270
}
82628271

82638272
if (hadLBrace && Tok.is(tok::r_brace)) {

0 commit comments

Comments
 (0)