Skip to content

Commit 8516c0c

Browse files
committed
Fix crash with failed typecheck
The walker was crashing if something failed to typecheck since the type wasn't available. I've added a little test to ensure that not only do we not crash, but continue checking within the closure.
1 parent 0fbbd89 commit 8516c0c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,9 @@ class CompletionHandlerUsageChecker final : public ASTWalker {
46294629
bool walkToDeclPre(Decl *D) override { return !isa<PatternBindingDecl>(D); }
46304630

46314631
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
4632+
if (expr->getType().isNull())
4633+
return {false, expr}; // Something failed to typecheck, bail out
4634+
46324635
if (ClosureExpr *closure = dyn_cast<ClosureExpr>(expr))
46334636
return {closure->isBodyAsync(), closure};
46344637

test/attr/attr_completionhandlerasync.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,9 @@ class ClassCallingAsyncStuff {
200200
}
201201
}
202202
}
203+
204+
func instanceFunc(other: ClassCallingAsyncStuff) async {
205+
// expected-error@+1{{cannot find 'c' in scope}}
206+
c.compHandlerFunc() { }
207+
}
203208
}

0 commit comments

Comments
 (0)