Skip to content

Commit b9f6405

Browse files
authored
Merge pull request #13727 from rudkx/iuo-decl-attr-on-failable-ctors
IUO: Set the IUO decl attribute on failable constructor decls.
2 parents 28af3a2 + 22f17a4 commit b9f6405

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4914,7 +4914,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
49144914
return cast<VarDecl>(accessor)->getTypeLoc();
49154915
}
49164916

4917-
static bool functionHasImplicitlyUnwrappedResult(FuncDecl *FD) {
4917+
static bool functionHasImplicitlyUnwrappedResult(AbstractFunctionDecl *AFD) {
4918+
if (auto *CD = dyn_cast<ConstructorDecl>(AFD)) {
4919+
return CD->getFailability() == OTK_ImplicitlyUnwrappedOptional;
4920+
}
4921+
4922+
auto *FD = cast<FuncDecl>(AFD);
49184923
if (FD->isAccessor() && !FD->isGetter())
49194924
return false;
49204925

@@ -7271,6 +7276,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
72717276

72727277
inferDynamic(TC.Context, CD);
72737278

7279+
if (functionHasImplicitlyUnwrappedResult(CD)) {
7280+
auto &C = CD->getASTContext();
7281+
CD->getAttrs().add(
7282+
new (C) ImplicitlyUnwrappedOptionalAttr(/* implicit= */ true));
7283+
}
7284+
72747285
TC.checkDeclAttributes(CD);
72757286
}
72767287

0 commit comments

Comments
 (0)