@@ -916,6 +916,24 @@ namespace {
916
916
917
917
Expr *selfOpenedRef = selfParamRef;
918
918
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
+
919
937
if (selfParamTy->hasOpenedExistential ()) {
920
938
// If we're opening an existential:
921
939
// - the type of 'ref' inside the closure is written in terms of the
@@ -931,31 +949,10 @@ namespace {
931
949
}
932
950
933
951
// (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);
959
956
960
957
if (selfParamRef->isSuperExpr ())
961
958
selfCall->setIsSuper (true );
@@ -7132,7 +7129,7 @@ ExprRewriter::buildDynamicCallable(ApplyExpr *apply, SelectedOverload selected,
7132
7129
7133
7130
// Construct expression referencing the `dynamicallyCall` method.
7134
7131
auto member = buildMemberRef (fn, SourceLoc (), selected,
7135
- DeclNameLoc (method-> getNameLoc () ), loc, loc,
7132
+ DeclNameLoc (), loc, loc,
7136
7133
/* implicit=*/ true , AccessSemantics::Ordinary);
7137
7134
7138
7135
// Construct argument to the method (either an array or dictionary
0 commit comments