|
20 | 20 | #include "swift/AST/Stmt.h"
|
21 | 21 | #include "swift/AST/Expr.h"
|
22 | 22 | #include "swift/AST/SourceFile.h"
|
| 23 | +#include "swift/AST/TypeCheckRequests.h" |
23 | 24 | #include "swift/AST/TypeRefinementContext.h"
|
24 | 25 | #include "swift/Basic/SourceManager.h"
|
25 | 26 |
|
@@ -192,6 +193,18 @@ TypeRefinementContext::findMostRefinedSubContext(SourceLoc Loc,
|
192 | 193 | !rangeContainsTokenLocWithGeneratedSource(SM, SrcRange, Loc))
|
193 | 194 | return nullptr;
|
194 | 195 |
|
| 196 | + // If this context is for a declaration, ensure that we've expanded the |
| 197 | + // children of the declaration. |
| 198 | + if (Node.getReason() == Reason::Decl || |
| 199 | + Node.getReason() == Reason::DeclImplicit) { |
| 200 | + if (auto decl = Node.getAsDecl()) { |
| 201 | + ASTContext &ctx = decl->getASTContext(); |
| 202 | + (void)evaluateOrDefault( |
| 203 | + ctx.evaluator, ExpandChildTypeRefinementContextsRequest{decl, this}, |
| 204 | + false); |
| 205 | + } |
| 206 | + } |
| 207 | + |
195 | 208 | // For the moment, we perform a linear search here, but we can and should
|
196 | 209 | // do something more efficient.
|
197 | 210 | for (TypeRefinementContext *Child : Children) {
|
@@ -354,6 +367,10 @@ void TypeRefinementContext::print(raw_ostream &OS, SourceManager &SrcMgr,
|
354 | 367 | OS << "extension." << ED->getExtendedType().getString();
|
355 | 368 | } else if (isa<TopLevelCodeDecl>(D)) {
|
356 | 369 | OS << "<top-level-code>";
|
| 370 | + } else if (auto PBD = dyn_cast<PatternBindingDecl>(D)) { |
| 371 | + if (auto VD = PBD->getAnchoringVarDecl(0)) { |
| 372 | + OS << VD->getName(); |
| 373 | + } |
357 | 374 | }
|
358 | 375 | }
|
359 | 376 |
|
@@ -411,3 +428,8 @@ StringRef TypeRefinementContext::getReasonName(Reason R) {
|
411 | 428 |
|
412 | 429 | llvm_unreachable("Unhandled Reason in switch.");
|
413 | 430 | }
|
| 431 | + |
| 432 | +void swift::simple_display( |
| 433 | + llvm::raw_ostream &out, const TypeRefinementContext *trc) { |
| 434 | + out << "TRC @" << trc; |
| 435 | +} |
0 commit comments