Skip to content

Commit 53685fe

Browse files
committed
parseUnion(): use ParserResult because; it returns at most one Decl, no need to
pass in a vector This a bit of noise to the diagnostics (see test change); this issue will be fixed uniformly for all nominal decls in future commits. Swift SVN r7399
1 parent 6613157 commit 53685fe

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class Parser {
453453
bool parseDeclImport(unsigned Flags, SmallVectorImpl<Decl*> &Decls);
454454
bool parseInheritance(SmallVectorImpl<TypeLoc> &Inherited);
455455
ParserResult<ExtensionDecl> parseDeclExtension(unsigned Flags);
456-
bool parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls);
456+
ParserResult<UnionDecl> parseDeclUnion(unsigned Flags);
457457
bool parseDeclUnionElement(unsigned Flags, SmallVectorImpl<Decl*> &Decls);
458458
bool parseNominalDeclMembers(SmallVectorImpl<Decl *> &memberDecls,
459459
SourceLoc LBLoc, SourceLoc &RBLoc,

lib/Parse/ParseDecl.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,10 @@ bool Parser::parseDecl(SmallVectorImpl<Decl*> &Entries, unsigned Flags) {
560560
HadParseError = true;
561561
break;
562562
case tok::kw_union:
563-
HadParseError = parseDeclUnion(Flags, Entries);
563+
if (Decl *D = parseDeclUnion(Flags).getPtrOrNull())
564+
Entries.push_back(D);
565+
else
566+
HadParseError = true;
564567
break;
565568
case tok::kw_case:
566569
HadParseError = parseDeclUnionElement(Flags, Entries);
@@ -1645,7 +1648,7 @@ bool Parser::parseDeclFuncBodyDelayed(FuncDecl *FD) {
16451648
/// decl-union-body:
16461649
/// decl*
16471650
///
1648-
bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
1651+
ParserResult<UnionDecl> Parser::parseDeclUnion(unsigned Flags) {
16491652
SourceLoc UnionLoc = consumeToken(tok::kw_union);
16501653

16511654
DeclAttributes Attributes;
@@ -1655,7 +1658,7 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
16551658
SourceLoc UnionNameLoc;
16561659
if (parseIdentifier(UnionName, UnionNameLoc,
16571660
diag::expected_identifier_in_decl, "union"))
1658-
return true;
1661+
return nullptr;
16591662

16601663
// Parse the generic-params, if present.
16611664
GenericParamList *GenericParams = nullptr;
@@ -1669,7 +1672,6 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
16691672
UnionName, UnionNameLoc,
16701673
{ },
16711674
GenericParams, CurDeclContext);
1672-
Decls.push_back(UD);
16731675

16741676
// Now that we have a context, update the generic parameters with that
16751677
// context.
@@ -1691,7 +1693,7 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
16911693
SourceLoc LBLoc, RBLoc;
16921694
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_union_type)) {
16931695
UD->setMembers({}, Tok.getLoc());
1694-
return true;
1696+
return makeParserErrorResult(UD);
16951697
}
16961698

16971699
bool Invalid = false;
@@ -1712,10 +1714,13 @@ bool Parser::parseDeclUnion(unsigned Flags, SmallVectorImpl<Decl*> &Decls) {
17121714

17131715
if (Flags & PD_DisallowNominalTypes) {
17141716
diagnose(UnionLoc, diag::disallowed_type);
1715-
return true;
1717+
return makeParserErrorResult(UD);
17161718
}
1717-
1718-
return Invalid;
1719+
1720+
if (Invalid)
1721+
return makeParserErrorResult(UD);
1722+
else
1723+
return makeParserResult(UD);
17191724
}
17201725

17211726
/// parseDeclUnionElement - Parse a 'case' of a union, returning true on error.

0 commit comments

Comments
 (0)