@@ -319,8 +319,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
319
319
CaseStmt /* nullable*/ *FallthroughDest = nullptr ;
320
320
FallthroughStmt /* nullable*/ *PreviousFallthrough = nullptr ;
321
321
322
- SourceLoc TargetTypeCheckLoc;
323
-
324
322
// / Used to distinguish the first BraceStmt that starts a TopLevelCodeDecl.
325
323
bool IsBraceStmtFromTopLevelDecl;
326
324
@@ -511,7 +509,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
511
509
512
510
TypeCheckExprOptions options = {};
513
511
514
- if (TargetTypeCheckLoc. isValid () ) {
512
+ if (getASTContext (). TypeCheckerOpts . TypeCheckSingleASTNode ) {
515
513
assert (DiagnosticSuppression::isEnabled (getASTContext ().Diags ) &&
516
514
" Diagnosing and AllowUnresolvedTypeVariables don't seem to mix" );
517
515
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
@@ -1558,7 +1556,7 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
1558
1556
(!ctx.LangOpts .Playground && !ctx.LangOpts .DebuggerSupport );
1559
1557
if (isDiscarded)
1560
1558
options |= TypeCheckExprFlags::IsDiscarded;
1561
- if (TargetTypeCheckLoc. isValid () )
1559
+ if (getASTContext (). TypeCheckerOpts . TypeCheckSingleASTNode )
1562
1560
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
1563
1561
1564
1562
auto resultTy =
@@ -1618,29 +1616,17 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
1618
1616
}
1619
1617
}
1620
1618
1621
- const SourceManager &SM = getASTContext ().SourceMgr ;
1622
- for (auto &elem : BS->getElements ()) {
1623
- if (TargetTypeCheckLoc.isValid ()) {
1624
- if (SM.isBeforeInBuffer (TargetTypeCheckLoc, elem.getStartLoc ()))
1625
- break ;
1626
-
1627
- // NOTE: We need to check the character loc here because the target loc
1628
- // can be inside the last token of the node. i.e. string interpolation.
1629
- SourceLoc endLoc = Lexer::getLocForEndOfToken (SM, elem.getEndLoc ());
1630
- if (endLoc == TargetTypeCheckLoc ||
1631
- SM.isBeforeInBuffer (endLoc, TargetTypeCheckLoc))
1632
- continue ;
1633
- }
1634
-
1619
+ for (auto &elem : BS->getElements ())
1635
1620
typeCheckASTNode (elem);
1636
- }
1637
1621
1638
1622
return BS;
1639
1623
}
1640
1624
1641
1625
void TypeChecker::typeCheckASTNode (ASTNode &node, DeclContext *DC) {
1642
1626
StmtChecker stmtChecker (DC);
1643
- stmtChecker.TargetTypeCheckLoc = node.getStartLoc ();
1627
+ // FIXME: 'ActiveLabeledStmts', 'SwitchLevel', etc. in StmtChecker are not
1628
+ // populated. Since they don't affect "type checking", it's doesn't cause
1629
+ // any issue for now. But it should be populated nonetheless.
1644
1630
stmtChecker.typeCheckASTNode (node);
1645
1631
}
1646
1632
@@ -1863,7 +1849,11 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(Evaluator &evaluator,
1863
1849
DeclContext *DC,
1864
1850
SourceLoc Loc) const {
1865
1851
auto &ctx = DC->getASTContext ();
1852
+ assert (DiagnosticSuppression::isEnabled (ctx.Diags ) &&
1853
+ " Diagnosing and Single ASTNode type checknig don't mix" );
1866
1854
1855
+ // Find innermost ASTNode at Loc from DC. Results the reference to the found
1856
+ // ASTNode and the decl context of it.
1867
1857
class ASTNodeFinder : public ASTWalker {
1868
1858
SourceManager &SM;
1869
1859
SourceLoc Loc;
0 commit comments