Skip to content

Commit 9c4c959

Browse files
committed
AST: Generalize CaptureListEntry::isSimpleSelfCapture() to work without parse-time lookup
The DeclRefExpr here was resolved by parse-time lookup. Without it, it's an UnresolvedDeclRefExpr.
1 parent 38883ce commit 9c4c959

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

lib/AST/Expr.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,13 +1228,30 @@ UnresolvedSpecializeExpr *UnresolvedSpecializeExpr::create(ASTContext &ctx,
12281228
}
12291229

12301230
bool CaptureListEntry::isSimpleSelfCapture() const {
1231+
auto &ctx = Var->getASTContext();
1232+
1233+
if (Var->getName() != ctx.Id_self)
1234+
return false;
1235+
1236+
if (auto *attr = Var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
1237+
if (attr->get() == ReferenceOwnership::Weak)
1238+
return false;
1239+
12311240
if (Init->getPatternList().size() != 1)
12321241
return false;
1233-
if (auto *DRE = dyn_cast<DeclRefExpr>(Init->getInit(0)))
1242+
1243+
auto *expr = Init->getInit(0);
1244+
1245+
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
12341246
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
1235-
return (VD->isSelfParameter() || VD->isSelfParamCapture())
1236-
&& VD->getName() == Var->getName();
1247+
return VD->getName() == ctx.Id_self;
12371248
}
1249+
}
1250+
1251+
if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(expr)) {
1252+
return UDRE->getName().isSimpleName(ctx.Id_self);
1253+
}
1254+
12381255
return false;
12391256
}
12401257

0 commit comments

Comments
 (0)