[CS] Fill in ErrorTypes for expressions that fail to type-check

Ensure we always produce typed AST, even if we
fail to apply a solution. This fixes a cursor info
issue where we'd to type-check a closure twice
due to it not having a type set.

rdar://129417672
This commit is contained in:
Hamish Knight
2024-06-17 17:58:52 +01:00
parent 9659601ecb
commit 5ec4d1cc98
4 changed files with 30 additions and 5 deletions

View File

@@ -303,9 +303,15 @@ bool SyntacticElementTarget::contextualTypeIsOnlyAHint() const {
void SyntacticElementTarget::markInvalid() const {
class InvalidationWalker : public ASTWalker {
ASTContext &Ctx;
public:
InvalidationWalker(ASTContext &ctx) : Ctx(ctx) {}
PreWalkResult<Expr *> walkToExprPre(Expr *E) override {
// TODO: We ought to fill in ErrorTypes for expressions here; ultimately
// type-checking should always produce typed AST.
if (!E->getType())
E->setType(ErrorType::get(Ctx));
return Action::Continue(E);
}
@@ -321,7 +327,7 @@ void SyntacticElementTarget::markInvalid() const {
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
}
};
InvalidationWalker walker;
InvalidationWalker walker(getDeclContext()->getASTContext());
walk(walker);
}