@@ -409,10 +409,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
409409 return std::nullopt ;
410410 }
411411
412- auto &diags = ctx.Diags ;
413- auto returnTypeRepr = afd->getResultTypeRepr ();
414- auto returnLoc = returnTypeRepr ? returnTypeRepr->getLoc () : afd->getLoc ();
415-
416412 if (hasEscapableResultOrYield (afd, resultType)) {
417413 return std::nullopt ;
418414 }
@@ -421,6 +417,11 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
421417 return std::nullopt ;
422418 }
423419
420+ auto &diags = ctx.Diags ;
421+ auto returnTypeRepr = afd->getResultTypeRepr ();
422+ auto returnLoc = returnTypeRepr ? returnTypeRepr->getLoc ()
423+ : afd->getLoc (/* SerializedOK */ false );
424+
424425 auto *cd = dyn_cast<ConstructorDecl>(afd);
425426 if (cd && cd->isImplicit ()) {
426427 if (cd->getParameters ()->size () == 0 ) {
@@ -438,7 +439,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
438439 auto selfOwnership = afd->getImplicitSelfDecl ()->getValueOwnership ();
439440 if (!isLifetimeDependenceCompatibleWithOwnership (kind, selfOwnership,
440441 afd)) {
441- diags.diagnose (afd-> getLoc () ,
442+ diags.diagnose (returnLoc ,
442443 diag::lifetime_dependence_invalid_self_ownership);
443444 return std::nullopt ;
444445 }
0 commit comments