Skip to content

Commit 3442a3a

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 f933552 commit 3442a3a

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
@@ -7913,8 +7913,9 @@ struct Parser::ParsedAccessors {
79137913

79147914
static ParserStatus parseAccessorIntroducer(Parser &P,
79157915
DeclAttributes &Attributes,
7916-
AccessorKind &Kind,
7917-
SourceLoc &Loc) {
7916+
AccessorKind &Kind, SourceLoc &Loc,
7917+
bool isFirstAccessor,
7918+
bool *featureUnavailable) {
79187919
ParserStatus Status;
79197920
assert(Attributes.isEmpty());
79207921
auto AttributeStatus = P.parseDeclAttributeList(Attributes);
@@ -8153,8 +8154,9 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81538154
DeclAttributes Attributes;
81548155
AccessorKind Kind = AccessorKind::Get;
81558156
SourceLoc Loc;
8156-
ParserStatus AccessorStatus =
8157-
parseAccessorIntroducer(*this, Attributes, Kind, Loc);
8157+
bool featureUnavailable = false;
8158+
ParserStatus AccessorStatus = parseAccessorIntroducer(
8159+
*this, Attributes, Kind, Loc, IsFirstAccessor, &featureUnavailable);
81588160
Status |= AccessorStatus;
81598161
if (AccessorStatus.isError() && !AccessorStatus.hasCodeCompletion()) {
81608162
if (Tok.is(tok::code_complete)) {
@@ -8181,7 +8183,9 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
81818183

81828184
// Cannot have an implicit getter after other accessor.
81838185
if (!IsFirstAccessor) {
8184-
diagnose(Tok, diag::expected_accessor_kw);
8186+
if (!featureUnavailable) {
8187+
diagnose(Tok, diag::expected_accessor_kw);
8188+
}
81858189
skipUntil(tok::r_brace);
81868190
// Don't signal an error since we recovered.
81878191
break;
@@ -8255,18 +8259,23 @@ void Parser::parseTopLevelAccessors(
82558259
ParserStatus status;
82568260
bool hasEffectfulGet = false;
82578261
bool parsingLimitedSyntax = false;
8262+
bool IsFirstAccessor = true;
82588263
while (!Tok.isAny(tok::r_brace, tok::eof)) {
82598264
DeclAttributes attributes;
82608265
AccessorKind kind = AccessorKind::Get;
82618266
SourceLoc loc;
82628267
ParserStatus accessorStatus =
8263-
parseAccessorIntroducer(*this, attributes, kind, loc);
8268+
parseAccessorIntroducer(*this, attributes, kind, loc, IsFirstAccessor,
8269+
/*featureUnavailable=*/nullptr);
82648270
if (accessorStatus.isError())
82658271
break;
82668272

82678273
(void)parseAccessorAfterIntroducer(loc, kind, accessors, hasEffectfulGet,
82688274
parsingLimitedSyntax, attributes,
82698275
PD_Default, storage, status);
8276+
if (IsFirstAccessor) {
8277+
IsFirstAccessor = false;
8278+
}
82708279
}
82718280

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

0 commit comments

Comments
 (0)