@@ -2007,17 +2007,37 @@ Expr *AutoClosureExpr::getSingleExpressionBody() const {
20072007}
20082008
20092009Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr () const {
2010+ auto maybeUnwrapOpenExistential = [](Expr *expr) {
2011+ if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
2012+ expr = openExistential->getSubExpr ()->getSemanticsProvidingExpr ();
2013+ if (auto *ICE = dyn_cast<ImplicitConversionExpr>(expr))
2014+ expr = ICE->getSyntacticSubExpr ();
2015+ }
2016+
2017+ return expr;
2018+ };
2019+
2020+ auto maybeUnwrapOptionalEval = [](Expr *expr) {
2021+ if (auto optEval = dyn_cast<OptionalEvaluationExpr>(expr))
2022+ expr = optEval->getSubExpr ();
2023+ if (auto inject = dyn_cast<InjectIntoOptionalExpr>(expr))
2024+ expr = inject->getSubExpr ();
2025+ if (auto erasure = dyn_cast<ErasureExpr>(expr))
2026+ expr = erasure->getSubExpr ();
2027+ if (auto bind = dyn_cast<BindOptionalExpr>(expr))
2028+ expr = bind->getSubExpr ();
2029+ return expr;
2030+ };
2031+
20102032 switch (getThunkKind ()) {
20112033 case AutoClosureExpr::Kind::None:
20122034 break ;
20132035
20142036 case AutoClosureExpr::Kind::SingleCurryThunk: {
20152037 auto *body = getSingleExpressionBody ();
20162038 body = body->getSemanticsProvidingExpr ();
2017-
2018- if (auto *openExistential = dyn_cast<OpenExistentialExpr>(body)) {
2019- body = openExistential->getSubExpr ()->getSemanticsProvidingExpr ();
2020- }
2039+ body = maybeUnwrapOpenExistential (body);
2040+ body = maybeUnwrapOptionalEval (body);
20212041
20222042 if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
20232043 return outerCall->getFn ();
@@ -2034,18 +2054,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
20342054 AutoClosureExpr::Kind::SingleCurryThunk);
20352055 auto *innerBody = innerClosure->getSingleExpressionBody ();
20362056 innerBody = innerBody->getSemanticsProvidingExpr ();
2037-
2038- if (auto *openExistential = dyn_cast<OpenExistentialExpr>(innerBody)) {
2039- innerBody = openExistential->getSubExpr ()->getSemanticsProvidingExpr ();
2040- if (auto *ICE = dyn_cast<ImplicitConversionExpr>(innerBody))
2041- innerBody = ICE->getSyntacticSubExpr ();
2042- }
2057+ innerBody = maybeUnwrapOpenExistential (innerBody);
2058+ innerBody = maybeUnwrapOptionalEval (innerBody);
20432059
20442060 if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
20452061 if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn ())) {
2046- if (auto *declRef = dyn_cast<DeclRefExpr>(innerCall->getFn ())) {
2047- return declRef;
2048- }
2062+ return innerCall->getFn ();
20492063 }
20502064 }
20512065 }
0 commit comments