Skip to content

Commit 58394ed

Browse files
committed
Parse: check if constructor decls are marked as convenience rather than (indirectly) calling getInitKind
When we requestify `getInitKind`, we don't want to invoke the request during parsing. What the parsing code really cares about is whether or not the decl has `ConvenienceAttr`.
1 parent 6e50c51 commit 58394ed

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6514,6 +6514,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
65146514
throwsLoc.isValid(), throwsLoc,
65156515
Params.get(), nullptr,
65166516
CurDeclContext);
6517+
CD->getAttrs() = Attributes;
65176518

65186519
// Parse a 'where' clause if present, adding it to our GenericParamList.
65196520
if (Tok.is(tok::kw_where)) {
@@ -6556,8 +6557,6 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
65566557
parseAbstractFunctionBody(CD);
65576558
}
65586559

6559-
CD->getAttrs() = Attributes;
6560-
65616560
return makeParserResult(CD);
65626561
}
65636562

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
468468
SourceLoc StartLoc = Tok.getLoc();
469469
auto CD = cast<ConstructorDecl>(CurDeclContext);
470470
// Hint at missing 'self.' or 'super.' then skip this statement.
471-
bool isSelf = !CD->isDesignatedInit() || !isa<ClassDecl>(CD->getParent());
471+
bool isSelf = CD->getAttrs().hasAttribute<ConvenienceAttr>() ||
472+
!isa<ClassDecl>(CD->getParent());
472473
diagnose(StartLoc, diag::invalid_nested_init, isSelf)
473474
.fixItInsert(StartLoc, isSelf ? "self." : "super.");
474475
NeedParseErrorRecovery = true;

0 commit comments

Comments
 (0)