@@ -916,6 +916,24 @@ namespace {
916916
917917 Expr *selfOpenedRef = selfParamRef;
918918
919+ // If the 'self' parameter has non-trivial ownership, adjust the
920+ // argument accordingly.
921+ switch (selfParam.getValueOwnership ()) {
922+ case ValueOwnership::Default:
923+ case ValueOwnership::InOut:
924+ break ;
925+
926+ case ValueOwnership::Owned:
927+ case ValueOwnership::Shared:
928+ // Ensure that the argument type matches up exactly.
929+ auto selfArgTy = ParenType::get (context,
930+ selfParam.getPlainType (),
931+ selfParam.getParameterFlags ());
932+ selfOpenedRef->setType (selfArgTy);
933+ cs.cacheType (selfOpenedRef);
934+ break ;
935+ }
936+
919937 if (selfParamTy->hasOpenedExistential ()) {
920938 // If we're opening an existential:
921939 // - the type of 'ref' inside the closure is written in terms of the
@@ -931,31 +949,10 @@ namespace {
931949 }
932950
933951 // (Self) -> ...
934- ApplyExpr *selfCall;
935-
936- // We build either a CallExpr or a DotSyntaxCallExpr depending on whether
937- // the base is implicit or not. This helps maintain some invariants around
938- // source ranges.
939- if (selfParamRef->isImplicit ()) {
940- selfCall =
941- CallExpr::createImplicit (context, ref, selfOpenedRef, {},
942- [&](Expr *E) { return cs.getType (E); });
943- selfCall->setType (refTy->getResult ());
944- cs.cacheType (selfCall);
945-
946- // FIXME: This is a holdover from the old tuple-based function call
947- // representation.
948- auto selfArgTy = ParenType::get (context,
949- selfParam.getPlainType (),
950- selfParam.getParameterFlags ());
951- selfCall->getArg ()->setType (selfArgTy);
952- cs.cacheType (selfCall->getArg ());
953- } else {
954- selfCall = new (context) DotSyntaxCallExpr (ref, SourceLoc (), selfOpenedRef);
955- selfCall->setImplicit (false );
956- selfCall->setType (refTy->getResult ());
957- cs.cacheType (selfCall);
958- }
952+ ApplyExpr *selfCall = new (context) DotSyntaxCallExpr (
953+ ref, SourceLoc (), selfOpenedRef);
954+ selfCall->setType (refTy->getResult ());
955+ cs.cacheType (selfCall);
959956
960957 if (selfParamRef->isSuperExpr ())
961958 selfCall->setIsSuper (true );
@@ -7132,7 +7129,7 @@ ExprRewriter::buildDynamicCallable(ApplyExpr *apply, SelectedOverload selected,
71327129
71337130 // Construct expression referencing the `dynamicallyCall` method.
71347131 auto member = buildMemberRef (fn, SourceLoc (), selected,
7135- DeclNameLoc (method-> getNameLoc () ), loc, loc,
7132+ DeclNameLoc (), loc, loc,
71367133 /* implicit=*/ true , AccessSemantics::Ordinary);
71377134
71387135 // Construct argument to the method (either an array or dictionary
0 commit comments