@@ -2007,17 +2007,37 @@ Expr *AutoClosureExpr::getSingleExpressionBody() const {
2007
2007
}
2008
2008
2009
2009
Expr *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
+
2010
2032
switch (getThunkKind ()) {
2011
2033
case AutoClosureExpr::Kind::None:
2012
2034
break ;
2013
2035
2014
2036
case AutoClosureExpr::Kind::SingleCurryThunk: {
2015
2037
auto *body = getSingleExpressionBody ();
2016
2038
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);
2021
2041
2022
2042
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
2023
2043
return outerCall->getFn ();
@@ -2034,18 +2054,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
2034
2054
AutoClosureExpr::Kind::SingleCurryThunk);
2035
2055
auto *innerBody = innerClosure->getSingleExpressionBody ();
2036
2056
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);
2043
2059
2044
2060
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
2045
2061
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 ();
2049
2063
}
2050
2064
}
2051
2065
}
0 commit comments