Skip to content

Commit 68f48ae

Browse files
authored
Merge pull request #41342 from xedin/adjust-availability-checking-for-se-326
[TypeChecker] SE-0326: Allow `ExprAvailabilityWalker` to walk into mu…
2 parents fc58b30 + 3fb0bb6 commit 68f48ae

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,16 +2849,7 @@ class ExprAvailabilityWalker : public ASTWalker {
28492849
}
28502850

28512851
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)) {
28622853
walkAbstractClosure(closure);
28632854
return skipChildren();
28642855
}
@@ -3006,6 +2997,24 @@ class ExprAvailabilityWalker : public ASTWalker {
30062997
walkInContext(E, E->getSubExpr(), MemberAccessContext::InOut);
30072998
}
30082999

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+
30093018
/// Walk an abstract closure expression, checking for availability
30103019
void walkAbstractClosure(AbstractClosureExpr *closure) {
30113020
// Do the walk with the closure set as the decl context of the 'where'

0 commit comments

Comments
 (0)