@@ -1836,6 +1836,12 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
18361836 return ;
18371837 }
18381838
1839+ if (auto *Cond = node.dyn_cast <StmtConditionElement *>()) {
1840+ bool IsFalsable; // ignored
1841+ TypeChecker::typeCheckStmtConditionElement (*Cond, IsFalsable, DC);
1842+ return ;
1843+ }
1844+
18391845 llvm_unreachable (" Type checking null ASTNode" );
18401846}
18411847
@@ -2163,6 +2169,19 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
21632169 class ASTNodeFinder : public ASTWalker {
21642170 SourceManager &SM;
21652171 SourceLoc Loc;
2172+
2173+ // / When the \c ASTNode that we want to check was found inside a brace
2174+ // / statement, we need to store a *reference* to the element in the
2175+ // / \c BraceStmt. When the brace statement gets type checked for result
2176+ // / builders its elements will be updated in-place, which makes
2177+ // / \c FoundNodeRef now point to the type-checked replacement node. We need
2178+ // / this behavior.
2179+ // /
2180+ // / But for all other cases, we just want to store a plain \c ASTNode. To
2181+ // / make sure we free the \c ASTNode again, we store it in
2182+ // / \c FoundNodeStorage and set \c FoundNodeRef to point to
2183+ // / \c FoundNodeStorage.
2184+ ASTNode FoundNodeStorage;
21662185 ASTNode *FoundNode = nullptr ;
21672186
21682187 // / The innermost DeclContext that contains \c FoundNode.
@@ -2230,6 +2249,20 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
22302249 }
22312250 // Already walked into.
22322251 return Action::Stop ();
2252+ } else if (auto Conditional = dyn_cast<LabeledConditionalStmt>(S)) {
2253+ for (StmtConditionElement &Cond : Conditional->getCond ()) {
2254+ if (SM.isBeforeInBuffer (Loc, Cond.getStartLoc ())) {
2255+ break ;
2256+ }
2257+ SourceLoc endLoc = Lexer::getLocForEndOfToken (SM, Cond.getEndLoc ());
2258+ if (SM.isBeforeInBuffer (endLoc, Loc) || endLoc == Loc) {
2259+ continue ;
2260+ }
2261+
2262+ FoundNodeStorage = ASTNode (&Cond);
2263+ FoundNode = &FoundNodeStorage;
2264+ return Action::Stop ();
2265+ }
22332266 }
22342267
22352268 return Action::Continue (S);
@@ -2270,7 +2303,8 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
22702303 SourceLoc endLoc = Lexer::getLocForEndOfToken (SM, D->getEndLoc ());
22712304 if (!(SM.isBeforeInBuffer (endLoc, Loc) || endLoc == Loc)) {
22722305 if (!isa<TopLevelCodeDecl>(D)) {
2273- FoundNode = new ASTNode (D);
2306+ FoundNodeStorage = ASTNode (D);
2307+ FoundNode = &FoundNodeStorage;
22742308 }
22752309 }
22762310 }
0 commit comments