@@ -353,7 +353,8 @@ ElementInfo makeElement(ASTNode node, ConstraintLocator *locator,
353
353
}
354
354
355
355
struct SyntacticElementContext
356
- : public llvm::PointerUnion<AbstractFunctionDecl *, AbstractClosureExpr *> {
356
+ : public llvm::PointerUnion<AbstractFunctionDecl *, AbstractClosureExpr *,
357
+ SingleValueStmtExpr *> {
357
358
// Inherit the constructors from PointerUnion.
358
359
using PointerUnion::PointerUnion;
359
360
@@ -373,11 +374,18 @@ struct SyntacticElementContext
373
374
return {func};
374
375
}
375
376
377
+ static SyntacticElementContext
378
+ forSingleValueStmtExpr (SingleValueStmtExpr *SVE) {
379
+ return {SVE};
380
+ }
381
+
376
382
DeclContext *getAsDeclContext () const {
377
383
if (auto *fn = this ->dyn_cast <AbstractFunctionDecl *>()) {
378
384
return fn;
379
385
} else if (auto *closure = this ->dyn_cast <AbstractClosureExpr *>()) {
380
386
return closure;
387
+ } else if (auto *SVE = dyn_cast<SingleValueStmtExpr *>()) {
388
+ return SVE->getDeclContext ();
381
389
} else {
382
390
llvm_unreachable (" unsupported kind" );
383
391
}
@@ -406,11 +414,13 @@ struct SyntacticElementContext
406
414
}
407
415
}
408
416
409
- BraceStmt * getBody () const {
417
+ Stmt * getStmt () const {
410
418
if (auto *fn = this ->dyn_cast <AbstractFunctionDecl *>()) {
411
419
return fn->getBody ();
412
420
} else if (auto *closure = this ->dyn_cast <AbstractClosureExpr *>()) {
413
421
return closure->getBody ();
422
+ } else if (auto *SVE = dyn_cast<SingleValueStmtExpr *>()) {
423
+ return SVE->getStmt ();
414
424
} else {
415
425
llvm_unreachable (" unsupported kind" );
416
426
}
@@ -1772,17 +1782,17 @@ class SyntacticElementSolutionApplication
1772
1782
#undef UNSUPPORTED_STMT
1773
1783
1774
1784
public:
1775
- // / Apply solution to the closure and return updated body .
1776
- ASTNode apply () {
1777
- auto body = visit (context.getBody ());
1785
+ // / Apply the solution to the context and return updated statement .
1786
+ Stmt * apply () {
1787
+ auto body = visit (context.getStmt ());
1778
1788
1779
1789
// Since local functions can capture variables that are declared
1780
1790
// after them, let's type-check them after all of the pattern
1781
1791
// bindings have been resolved by applying solution to the body.
1782
1792
for (auto *func : LocalFuncs)
1783
1793
TypeChecker::typeCheckDecl (func);
1784
1794
1785
- return body;
1795
+ return body ? body. get <Stmt *>() : nullptr ;
1786
1796
}
1787
1797
};
1788
1798
@@ -1799,7 +1809,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
1799
1809
Transform (transform) {}
1800
1810
1801
1811
bool apply () {
1802
- auto body = visit (context.getBody ());
1812
+ auto body = visit (context.getStmt ());
1803
1813
1804
1814
if (!body || hadError)
1805
1815
return true ;
@@ -2193,13 +2203,12 @@ bool ConstraintSystem::applySolutionToBody(Solution &solution,
2193
2203
solution, SyntacticElementContext::forFunctionRef (fn), resultTy,
2194
2204
rewriteTarget);
2195
2205
2196
- auto body = application.apply ();
2206
+ auto * body = application.apply ();
2197
2207
2198
2208
if (!body || application.hadError )
2199
2209
return true ;
2200
2210
2201
- fn.setTypecheckedBody (castToStmt<BraceStmt>(body),
2202
- fn.hasSingleExpressionBody ());
2211
+ fn.setTypecheckedBody (cast<BraceStmt>(body), fn.hasSingleExpressionBody ());
2203
2212
return false ;
2204
2213
}
2205
2214
0 commit comments