Skip to content

Commit 985e8d9

Browse files
committed
Update DeclContext::getInnermostClosureForSelfCapture to return a ClosureExpr
1 parent 74a33eb commit 985e8d9

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

include/swift/AST/DeclContext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace swift {
8282
class SerializedTopLevelCodeDecl;
8383
class StructDecl;
8484
class AccessorDecl;
85+
class ClosureExpr;
8586

8687
template <typename T>
8788
struct AvailableDuringLoweringDeclFilter;
@@ -507,8 +508,8 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
507508
/// Returns the innermost context that is a ClosureExpr, which defines how
508509
/// self behaves, unless within a type context that redefines self.
509510
LLVM_READONLY
510-
DeclContext *getInnermostClosureForSelfCapture();
511-
const DeclContext *getInnermostClosureForSelfCapture() const {
511+
ClosureExpr *getInnermostClosureForSelfCapture();
512+
const ClosureExpr *getInnermostClosureForSelfCapture() const {
512513
return const_cast<DeclContext *>(this)->getInnermostClosureForSelfCapture();
513514
}
514515

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ DeclContext *DeclContext::getInnermostSkippedFunctionContext() {
263263
return nullptr;
264264
}
265265

266-
DeclContext *DeclContext::getInnermostClosureForSelfCapture() {
266+
ClosureExpr *DeclContext::getInnermostClosureForSelfCapture() {
267267
auto dc = this;
268268
if (auto closure = dyn_cast<ClosureExpr>(dc)) {
269269
return closure;

lib/AST/UnqualifiedLookup.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ ValueDecl *UnqualifiedLookupFactory::lookupBaseDecl(const DeclContext *baseDC) c
355355
// Perform an unqualified lookup for the base decl of this result. This
356356
// handles cases where self was rebound (e.g. `guard let self = self`)
357357
// earlier in this closure or some outer closure.
358-
auto closureExpr =
359-
dyn_cast_or_null<ClosureExpr>(DC->getInnermostClosureForSelfCapture());
358+
auto closureExpr = DC->getInnermostClosureForSelfCapture();
360359
if (!closureExpr) {
361360
return nullptr;
362361
}

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,8 +2101,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
21012101
return nullptr;
21022102
}
21032103

2104-
return dyn_cast_or_null<const ClosureExpr>(
2105-
parentContext->getInnermostClosureForSelfCapture());
2104+
return parentContext->getInnermostClosureForSelfCapture();
21062105
}
21072106

21082107
bool shouldWalkCaptureInitializerExpressions() override { return true; }

0 commit comments

Comments
 (0)