Skip to content

Commit 3fcc5a8

Browse files
committed
Always validate self capture
1 parent 3315cab commit 3fcc5a8

File tree

4 files changed

+405
-105
lines changed

4 files changed

+405
-105
lines changed

lib/AST/UnqualifiedLookup.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ ValueDecl *UnqualifiedLookupFactory::lookupBaseDecl(const DeclContext *baseDC) c
399399
// In these cases, using the Swift 6 lookup behavior doesn't affect
400400
// how the body is type-checked, so it can be used in Swift 5 mode
401401
// without breaking source compatibility for non-escaping closures.
402-
if (capturesSelfWeakly && Ctx.LangOpts.isSwiftVersionAtLeast(6) &&
402+
if (capturesSelfWeakly && !Ctx.LangOpts.isSwiftVersionAtLeast(6) &&
403403
!implicitSelfReferenceIsUnwrapped(selfDecl)) {
404404
return nullptr;
405405
}
@@ -416,10 +416,13 @@ ValueDecl *UnqualifiedLookupFactory::lookupBaseDecl(const DeclContext *baseDC) c
416416
//
417417
// Other types of rebindings, like an arbitrary "let `self` = foo",
418418
// are never allowed to rebind self.
419-
if (auto var = dyn_cast<VarDecl>(selfDecl)) {
420-
if (!(var->isCaptureList() || var->getParentPatternStmt())) {
421-
return nullptr;
422-
}
419+
auto selfVD = dyn_cast<VarDecl>(selfDecl);
420+
if (!selfVD) {
421+
return nullptr;
422+
}
423+
424+
if (!(selfVD->isCaptureList() || selfVD->getParentPatternStmt())) {
425+
return nullptr;
423426
}
424427

425428
return selfDecl;

0 commit comments

Comments
 (0)