Skip to content

Commit 8ec878b

Browse files
committed
Sema: Use ASTScope::lookupSingleLocalDecl() in CSGen's CollectVarRefs pass
When parse-time lookup is disabled, we have to resolve UnresolvedDeclRefExprs inside the closure body, since there's no guarantee that preCheckExpression() has run yet.
1 parent dcafd58 commit 8ec878b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,24 @@ namespace {
25522552
}
25532553
}
25542554

2555+
// FIXME: We can see UnresolvedDeclRefExprs here because we have
2556+
// not yet run preCheckExpression() on the entire closure body
2557+
// yet.
2558+
//
2559+
// We could consider pre-checking more eagerly.
2560+
if (auto *declRef = dyn_cast<UnresolvedDeclRefExpr>(expr)) {
2561+
auto name = declRef->getName();
2562+
auto loc = declRef->getLoc();
2563+
if (name.isSimpleName() && loc.isValid()) {
2564+
auto *varDecl = dyn_cast_or_null<VarDecl>(
2565+
ASTScope::lookupSingleLocalDecl(cs.DC->getParentSourceFile(),
2566+
name.getFullName(), loc));
2567+
if (varDecl)
2568+
if (auto varType = cs.getTypeIfAvailable(varDecl))
2569+
varType->getTypeVariables(varRefs);
2570+
}
2571+
}
2572+
25552573
return { true, expr };
25562574
}
25572575
} collectVarRefs(CS);

0 commit comments

Comments
 (0)