Skip to content

Commit f2d426f

Browse files
authored
[AST] CaptureListExpr's body is always a ClosureExpr (#7326)
1 parent 163f58e commit f2d426f

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

include/swift/AST/Expr.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,48 +3256,6 @@ class SequenceExpr final : public Expr,
32563256
};
32573257

32583258

3259-
/// Instances of this structure represent elements of the capture list that can
3260-
/// optionally occur in a capture expression.
3261-
struct CaptureListEntry {
3262-
VarDecl *Var;
3263-
PatternBindingDecl *Init;
3264-
3265-
CaptureListEntry(VarDecl *Var, PatternBindingDecl *Init)
3266-
: Var(Var), Init(Init) {
3267-
}
3268-
};
3269-
3270-
/// CaptureListExpr - This expression represents the capture list on an explicit
3271-
/// closure. Because the capture list is evaluated outside of the closure, this
3272-
/// CaptureList wraps the ClosureExpr. The dynamic semantics are that evaluates
3273-
/// the variable bindings from the capture list, then evaluates the
3274-
/// subexpression (the closure itself) and returns the result.
3275-
class CaptureListExpr : public Expr {
3276-
ArrayRef<CaptureListEntry> captureList;
3277-
Expr *closureBody;
3278-
public:
3279-
CaptureListExpr(ArrayRef<CaptureListEntry> captureList, Expr *closureBody)
3280-
: Expr(ExprKind::CaptureList, /*Implicit=*/false, Type()),
3281-
captureList(captureList), closureBody(closureBody) {
3282-
}
3283-
3284-
ArrayRef<CaptureListEntry> getCaptureList() { return captureList; }
3285-
Expr *getClosureBody() { return closureBody; }
3286-
const Expr *getClosureBody() const { return closureBody; }
3287-
3288-
void setClosureBody(Expr *body) { closureBody = body; }
3289-
3290-
/// This is a bit weird, but the capture list is lexically contained within
3291-
/// the closure, so the ClosureExpr has the full source range.
3292-
SWIFT_FORWARD_SOURCE_LOCS_TO(closureBody)
3293-
3294-
// Implement isa/cast/dyncast/etc.
3295-
static bool classof(const Expr *E) {
3296-
return E->getKind() == ExprKind::CaptureList;
3297-
}
3298-
};
3299-
3300-
33013259
/// \brief A base class for closure expressions.
33023260
class AbstractClosureExpr : public Expr, public DeclContext {
33033261
CaptureInfo Captures;
@@ -3607,6 +3565,48 @@ class AutoClosureExpr : public AbstractClosureExpr {
36073565
}
36083566
};
36093567

3568+
/// Instances of this structure represent elements of the capture list that can
3569+
/// optionally occur in a capture expression.
3570+
struct CaptureListEntry {
3571+
VarDecl *Var;
3572+
PatternBindingDecl *Init;
3573+
3574+
CaptureListEntry(VarDecl *Var, PatternBindingDecl *Init)
3575+
: Var(Var), Init(Init) {
3576+
}
3577+
};
3578+
3579+
/// CaptureListExpr - This expression represents the capture list on an explicit
3580+
/// closure. Because the capture list is evaluated outside of the closure, this
3581+
/// CaptureList wraps the ClosureExpr. The dynamic semantics are that evaluates
3582+
/// the variable bindings from the capture list, then evaluates the
3583+
/// subexpression (the closure itself) and returns the result.
3584+
class CaptureListExpr : public Expr {
3585+
ArrayRef<CaptureListEntry> captureList;
3586+
ClosureExpr *closureBody;
3587+
public:
3588+
CaptureListExpr(ArrayRef<CaptureListEntry> captureList,
3589+
ClosureExpr *closureBody)
3590+
: Expr(ExprKind::CaptureList, /*Implicit=*/false, Type()),
3591+
captureList(captureList), closureBody(closureBody) {
3592+
}
3593+
3594+
ArrayRef<CaptureListEntry> getCaptureList() { return captureList; }
3595+
ClosureExpr *getClosureBody() { return closureBody; }
3596+
const ClosureExpr *getClosureBody() const { return closureBody; }
3597+
3598+
void setClosureBody(ClosureExpr *body) { closureBody = body; }
3599+
3600+
/// This is a bit weird, but the capture list is lexically contained within
3601+
/// the closure, so the ClosureExpr has the full source range.
3602+
SWIFT_FORWARD_SOURCE_LOCS_TO(closureBody)
3603+
3604+
// Implement isa/cast/dyncast/etc.
3605+
static bool classof(const Expr *E) {
3606+
return E->getKind() == ExprKind::CaptureList;
3607+
}
3608+
};
3609+
36103610
/// DynamicTypeExpr - "type(of: base)" - Produces a metatype value.
36113611
///
36123612
/// The metatype value comes from evaluating an expression then retrieving the

lib/AST/ASTWalker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
660660
return nullptr;
661661
}
662662

663-
Expr *body = expr->getClosureBody();
664-
if ((body = doIt(body)))
663+
ClosureExpr *body = expr->getClosureBody();
664+
if ((body = cast_or_null<ClosureExpr>(doIt(body))))
665665
expr->setClosureBody(body);
666666
else
667667
return nullptr;

0 commit comments

Comments
 (0)