|
31 | 31 | using namespace swift; |
32 | 32 | using namespace ide; |
33 | 33 |
|
34 | | -//===----------------------------------------------------------------------===// |
35 | | -// prepareForRetypechecking(Expr *) |
36 | | -//===----------------------------------------------------------------------===// |
37 | | - |
38 | | -/// Prepare the given expression for type-checking again, prinicipally by |
39 | | -/// erasing any ErrorType types on the given expression, allowing later |
40 | | -/// type-checking to make progress. |
41 | | -/// |
42 | | -/// FIXME: this is fundamentally a workaround for the fact that we may end up |
43 | | -/// typechecking parts of an expression more than once - first for checking |
44 | | -/// the context, and later for checking more-specific things like unresolved |
45 | | -/// members. We should restructure code-completion type-checking so that we |
46 | | -/// never typecheck more than once (or find a more principled way to do it). |
47 | | -void swift::ide::prepareForRetypechecking(Expr *E) { |
48 | | - assert(E); |
49 | | - struct Eraser : public ASTWalker { |
50 | | - std::pair<bool, Expr *> walkToExprPre(Expr *expr) override { |
51 | | - if (expr && expr->getType() && (expr->getType()->hasError() || |
52 | | - expr->getType()->hasUnresolvedType())) |
53 | | - expr->setType(Type()); |
54 | | - if (auto *ACE = dyn_cast_or_null<AutoClosureExpr>(expr)) { |
55 | | - return { true, ACE->getSingleExpressionBody() }; |
56 | | - } |
57 | | - return { true, expr }; |
58 | | - } |
59 | | - bool walkToTypeLocPre(TypeLoc &TL) override { |
60 | | - if (TL.getType() && (TL.getType()->hasError() || |
61 | | - TL.getType()->hasUnresolvedType())) |
62 | | - TL.setType(Type()); |
63 | | - return true; |
64 | | - } |
65 | | - |
66 | | - std::pair<bool, Pattern*> walkToPatternPre(Pattern *P) override { |
67 | | - if (P && P->hasType() && (P->getType()->hasError() || |
68 | | - P->getType()->hasUnresolvedType())) { |
69 | | - P->setType(Type()); |
70 | | - } |
71 | | - return { true, P }; |
72 | | - } |
73 | | - std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override { |
74 | | - return { false, S }; |
75 | | - } |
76 | | - }; |
77 | | - |
78 | | - E->walk(Eraser()); |
79 | | -} |
80 | | - |
81 | 34 | //===----------------------------------------------------------------------===// |
82 | 35 | // typeCheckContextUntil(DeclContext, SourceLoc) |
83 | 36 | //===----------------------------------------------------------------------===// |
|
0 commit comments