@@ -914,6 +914,35 @@ namespace {
914
914
};
915
915
} // end anonymous namespace
916
916
917
+ namespace {
918
+ // Check if \p E is a call expression to curried thunk of "KeyPath as function".
919
+ // i.e. '{ `$kp$` in { $0[keyPath: $kp$] } }(keypath)'
920
+ static bool isKeyPathCurriedThunkCallExpr (Expr *E) {
921
+ auto CE = dyn_cast<CallExpr>(E);
922
+ if (!CE)
923
+ return false ;
924
+ auto thunk = dyn_cast<AutoClosureExpr>(CE->getFn ());
925
+ if (!thunk)
926
+ return false ;
927
+ if (thunk->getParameters ()->size () != 1 ||
928
+ thunk->getParameters ()->get (0 )->getParameterName ().str () != " $kp$" )
929
+ return false ;
930
+
931
+ auto PE = dyn_cast<ParenExpr>(CE->getArg ());
932
+ if (!PE)
933
+ return false ;
934
+ return isa<KeyPathExpr>(PE->getSubExpr ());
935
+ }
936
+
937
+ // Extract the keypath expression from the curried thunk expression.
938
+ static Expr *extractKeyPathFromCurryThunkCall (Expr *E) {
939
+ assert (isKeyPathCurriedThunkCallExpr (E));
940
+ auto call = cast<CallExpr>(E);
941
+ auto arg = cast<ParenExpr>(call->getArg ());
942
+ return arg->getSubExpr ();
943
+ }
944
+ } // end anonymous namespace
945
+
917
946
namespace {
918
947
919
948
class ConstraintGenerator : public ExprVisitor <ConstraintGenerator, Type> {
@@ -3781,13 +3810,20 @@ namespace {
3781
3810
continue ;
3782
3811
}
3783
3812
3813
+ // Extract keypath from '{ `$kp$` in { $0[keyPath: $kp$] } }(keypath)'
3814
+ if (isKeyPathCurriedThunkCallExpr (expr)) {
3815
+ expr = extractKeyPathFromCurryThunkCall (expr);
3816
+ continue ;
3817
+ }
3818
+
3784
3819
// Restore '@autoclosure'd value.
3785
3820
if (auto ACE = dyn_cast<AutoClosureExpr>(expr)) {
3786
3821
// This is only valid if the closure doesn't have parameters.
3787
3822
if (ACE->getParameters ()->size () == 0 ) {
3788
3823
expr = ACE->getSingleExpressionBody ();
3789
3824
continue ;
3790
3825
}
3826
+ llvm_unreachable (" other AutoClosureExpr must be handled specially" );
3791
3827
}
3792
3828
3793
3829
// Remove any semantic expression injected by typechecking.
0 commit comments