@@ -927,20 +927,31 @@ namespace {
927927 }
928928
929929 // (Self) -> ...
930- auto *selfCall =
931- CallExpr::createImplicit (context, ref, selfOpenedRef, { },
932- [&](const Expr *E) { return cs.getType (E); });
933- selfCall->setType (refTy->getResult ());
934- cs.cacheType (selfCall->getArg ());
935- cs.cacheType (selfCall);
936-
937- // FIXME: This is a holdover from the old tuple-based function call
938- // representation.
939- auto selfArgTy = ParenType::get (context,
940- selfParam.getPlainType (),
941- selfParam.getParameterFlags ());
942- selfCall->getArg ()->setType (selfArgTy);
943- cs.cacheType (selfCall->getArg ());
930+ ApplyExpr *selfCall;
931+
932+ // We build either a CallExpr or a DotSyntaxCallExpr depending on whether
933+ // the base is implicit or not. This helps maintain some invariants around
934+ // source ranges.
935+ if (selfParamRef->isImplicit ()) {
936+ selfCall =
937+ CallExpr::createImplicit (context, ref, selfOpenedRef, { },
938+ [&](const Expr *E) { return cs.getType (E); });
939+ selfCall->setType (refTy->getResult ());
940+ cs.cacheType (selfCall);
941+
942+ // FIXME: This is a holdover from the old tuple-based function call
943+ // representation.
944+ auto selfArgTy = ParenType::get (context,
945+ selfParam.getPlainType (),
946+ selfParam.getParameterFlags ());
947+ selfCall->getArg ()->setType (selfArgTy);
948+ cs.cacheType (selfCall->getArg ());
949+ } else {
950+ selfCall = new (context) DotSyntaxCallExpr (ref, SourceLoc (), selfOpenedRef);
951+ selfCall->setImplicit (false );
952+ selfCall->setType (refTy->getResult ());
953+ cs.cacheType (selfCall);
954+ }
944955
945956 if (selfParamRef->isSuperExpr ())
946957 selfCall->setIsSuper (true );
0 commit comments