Skip to content

Commit be94e5d

Browse files
committed
[CS] NFC: Sink LocalDeclsToTypeCheck into ExprRewriter
1 parent caceca6 commit be94e5d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/Sema/CSApply.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ namespace {
408408
/// Rewrites an expression by applying the solution of a constraint
409409
/// system to that expression.
410410
class ExprRewriter : public ExprVisitor<ExprRewriter, Expr *> {
411+
// Delayed items to type-check.
412+
SmallVector<Decl *, 4> LocalDeclsToTypeCheck;
413+
411414
public:
412415
ConstraintSystem &cs;
413416
DeclContext *dc;
@@ -424,6 +427,10 @@ namespace {
424427

425428
ConstraintSystem &getConstraintSystem() const { return cs; }
426429

430+
void addLocalDeclToTypeCheck(Decl *D) {
431+
LocalDeclsToTypeCheck.push_back(D);
432+
}
433+
427434
/// Coerce the given tuple to another tuple type.
428435
///
429436
/// \param expr The expression we're converting.
@@ -5604,6 +5611,10 @@ namespace {
56045611
diag::add_consume_to_silence)
56055612
.fixItInsert(coercion->getStartLoc(), "consume ");
56065613
}
5614+
5615+
// Type-check any local decls encountered.
5616+
for (auto *D : LocalDeclsToTypeCheck)
5617+
TypeChecker::typeCheckDecl(D);
56075618
}
56085619

56095620
/// Diagnose an optional injection that is probably not what the
@@ -8805,22 +8816,15 @@ namespace {
88058816

88068817
class ExprWalker : public ASTWalker, public SyntacticElementTargetRewriter {
88078818
ExprRewriter &Rewriter;
8808-
SmallVector<Decl *, 4> LocalDeclsToTypeCheck;
88098819

88108820
public:
88118821
ExprWalker(ExprRewriter &Rewriter) : Rewriter(Rewriter) { }
88128822

8813-
~ExprWalker() {
8814-
// Type-check any local decls encountered.
8815-
for (auto *D : LocalDeclsToTypeCheck)
8816-
TypeChecker::typeCheckDecl(D);
8817-
}
8818-
88198823
Solution &getSolution() const override { return Rewriter.solution; }
88208824
DeclContext *&getCurrentDC() const override { return Rewriter.dc; }
88218825

88228826
void addLocalDeclToTypeCheck(Decl *D) override {
8823-
LocalDeclsToTypeCheck.push_back(D);
8827+
Rewriter.addLocalDeclToTypeCheck(D);
88248828
}
88258829

88268830
bool shouldWalkIntoPropertyWrapperPlaceholderValue() override {

0 commit comments

Comments
 (0)