@@ -1836,6 +1836,12 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
1836
1836
return ;
1837
1837
}
1838
1838
1839
+ if (auto *Cond = node.dyn_cast <StmtConditionElement *>()) {
1840
+ bool IsFalsable; // ignored
1841
+ TypeChecker::typeCheckStmtConditionElement (*Cond, IsFalsable, DC);
1842
+ return ;
1843
+ }
1844
+
1839
1845
llvm_unreachable (" Type checking null ASTNode" );
1840
1846
}
1841
1847
@@ -2163,6 +2169,19 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
2163
2169
class ASTNodeFinder : public ASTWalker {
2164
2170
SourceManager &SM;
2165
2171
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;
2166
2185
ASTNode *FoundNode = nullptr ;
2167
2186
2168
2187
// / The innermost DeclContext that contains \c FoundNode.
@@ -2230,6 +2249,20 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
2230
2249
}
2231
2250
// Already walked into.
2232
2251
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
+ }
2233
2266
}
2234
2267
2235
2268
return Action::Continue (S);
@@ -2270,7 +2303,8 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
2270
2303
SourceLoc endLoc = Lexer::getLocForEndOfToken (SM, D->getEndLoc ());
2271
2304
if (!(SM.isBeforeInBuffer (endLoc, Loc) || endLoc == Loc)) {
2272
2305
if (!isa<TopLevelCodeDecl>(D)) {
2273
- FoundNode = new ASTNode (D);
2306
+ FoundNodeStorage = ASTNode (D);
2307
+ FoundNode = &FoundNodeStorage;
2274
2308
}
2275
2309
}
2276
2310
}
0 commit comments