Skip to content

Commit 17e6a25

Browse files
committed
[Parse] Accumulate a parser status while parsing attributes
1 parent ee85314 commit 17e6a25

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
27982798
// diagnostic this can be used for better error presentation.
27992799
SourceRange AttrRange;
28002800

2801+
ParserStatus Status;
2802+
28012803
switch (DK) {
28022804
case DAK_Count:
28032805
llvm_unreachable("DAK_Count should not appear in parsing switch");
@@ -3583,16 +3585,16 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
35833585
case DAK_StorageRestrictions: {
35843586
ParserResult<StorageRestrictionsAttr> Attr =
35853587
parseStorageRestrictionsAttribute(AtLoc, Loc);
3586-
if (!Attr.isParseErrorOrHasCompletion()) {
3588+
Status |= Attr;
3589+
if (Attr.isNonNull()) {
35873590
Attributes.add(Attr.get());
3588-
} else {
3589-
return Attr;
35903591
}
35913592
break;
35923593
}
35933594

35943595
case DAK_Implements: {
35953596
ParserResult<ImplementsAttr> Attr = parseImplementsAttribute(AtLoc, Loc);
3597+
Status |= Attr;
35963598
if (Attr.isNonNull()) {
35973599
Attributes.add(Attr.get());
35983600
}
@@ -3601,6 +3603,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36013603

36023604
case DAK_Differentiable: {
36033605
auto Attr = parseDifferentiableAttribute(AtLoc, Loc);
3606+
Status |= Attr;
36043607
if (Attr.isNonNull())
36053608
Attributes.add(Attr.get());
36063609
break;
@@ -3612,6 +3615,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36123615
diagnose(Loc, diag::attr_only_at_non_local_scope, '@' + AttrName.str());
36133616

36143617
auto Attr = parseDerivativeAttribute(AtLoc, Loc);
3618+
Status |= Attr;
36153619
if (Attr.isNonNull())
36163620
Attributes.add(Attr.get());
36173621
break;
@@ -3623,6 +3627,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36233627
diagnose(Loc, diag::attr_only_at_non_local_scope, '@' + AttrName.str());
36243628

36253629
auto Attr = parseTransposeAttribute(AtLoc, Loc);
3630+
Status |= Attr;
36263631
if (Attr.isNonNull())
36273632
Attributes.add(Attr.get());
36283633
break;
@@ -3693,6 +3698,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36933698
}
36943699
case DAK_Documentation: {
36953700
auto Attr = parseDocumentationAttribute(AtLoc, Loc);
3701+
Status |= Attr;
36963702
if (Attr.isNonNull())
36973703
Attributes.add(Attr.get());
36983704
else
@@ -3703,6 +3709,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
37033709
auto syntax = (AttrName == "freestanding" ? MacroSyntax::Freestanding
37043710
: MacroSyntax::Attached);
37053711
auto Attr = parseMacroRoleAttribute(syntax, AtLoc, Loc);
3712+
Status |= Attr;
37063713
if (Attr.isNonNull())
37073714
Attributes.add(Attr.get());
37083715
else
@@ -3861,7 +3868,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
38613868
if (AtLoc.isValid() && DeclAttribute::isDeclModifier(DK))
38623869
diagnose(AtLoc, diag::cskeyword_not_attribute, AttrName).fixItRemove(AtLoc);
38633870

3864-
return makeParserSuccess();
3871+
return Status;
38653872
}
38663873

38673874
bool Parser::parseVersionTuple(llvm::VersionTuple &Version,

test/decl/var/init_accessors.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ func test_invalid_storage_restrictions() {
621621
var c: Int {
622622
@storageRestrictions(initializes: a, initializes: b)
623623
// expected-error@-1 {{duplicate label 'initializes' in @storageRestrictions attribute}}
624+
// expected-error@-2 {{init accessor cannot refer to property 'a'; init accessors can refer only to stored properties}}
624625
init {}
625626

626627
get { 0 }
@@ -629,6 +630,7 @@ func test_invalid_storage_restrictions() {
629630
var d: Int {
630631
@storageRestrictions(accesses: a, accesses: c)
631632
// expected-error@-1 {{duplicate label 'accesses' in @storageRestrictions attribute}}
633+
// expected-error@-2 {{init accessor cannot refer to property 'a'; init accessors can refer only to stored properties}}
632634
init {}
633635

634636
get { 0 }

0 commit comments

Comments
 (0)