@@ -2849,16 +2849,7 @@ class ExprAvailabilityWalker : public ASTWalker {
2849
2849
}
2850
2850
2851
2851
if (AbstractClosureExpr *closure = dyn_cast<AbstractClosureExpr>(E)) {
2852
- // Multi-statement closures are collected by ExprWalker::rewriteFunction
2853
- // and checked by ExprWalker::processDelayed in CSApply.cpp.
2854
- // Single-statement closures only have the attributes checked
2855
- // by TypeChecker::checkClosureAttributes in that rewriteFunction.
2856
- // Multi-statement closures will be checked explicitly later (as the decl
2857
- // context in the Where). Single-expression closures will not be
2858
- // revisited, and are not automatically set as the context of the 'where'.
2859
- // Don't double-check multi-statement closures, but do check
2860
- // single-statement closures, setting the closure as the decl context.
2861
- if (closure->hasSingleExpressionBody ()) {
2852
+ if (shouldWalkIntoClosure (closure)) {
2862
2853
walkAbstractClosure (closure);
2863
2854
return skipChildren ();
2864
2855
}
@@ -3006,6 +2997,24 @@ class ExprAvailabilityWalker : public ASTWalker {
3006
2997
walkInContext (E, E->getSubExpr (), MemberAccessContext::InOut);
3007
2998
}
3008
2999
3000
+ bool shouldWalkIntoClosure (AbstractClosureExpr *closure) const {
3001
+ // Multi-statement closures are collected by ExprWalker::rewriteFunction
3002
+ // and checked by ExprWalker::processDelayed in CSApply.cpp.
3003
+ // Single-statement closures only have the attributes checked
3004
+ // by TypeChecker::checkClosureAttributes in that rewriteFunction.
3005
+ // Multi-statement closures will be checked explicitly later (as the decl
3006
+ // context in the Where). Single-expression closures will not be
3007
+ // revisited, and are not automatically set as the context of the 'where'.
3008
+ // Don't double-check multi-statement closures, but do check
3009
+ // single-statement closures, setting the closure as the decl context.
3010
+ //
3011
+ // Note about SE-0326: When a flag is enabled multi-statement closures
3012
+ // are type-checked together with enclosing context, so walker behavior
3013
+ // should match that of single-expression closures.
3014
+ return closure->hasSingleExpressionBody () ||
3015
+ Context.TypeCheckerOpts .EnableMultiStatementClosureInference ;
3016
+ }
3017
+
3009
3018
// / Walk an abstract closure expression, checking for availability
3010
3019
void walkAbstractClosure (AbstractClosureExpr *closure) {
3011
3020
// Do the walk with the closure set as the decl context of the 'where'
0 commit comments