@@ -409,10 +409,6 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
409
409
return std::nullopt;
410
410
}
411
411
412
- auto &diags = ctx.Diags ;
413
- auto returnTypeRepr = afd->getResultTypeRepr ();
414
- auto returnLoc = returnTypeRepr ? returnTypeRepr->getLoc () : afd->getLoc ();
415
-
416
412
if (hasEscapableResultOrYield (afd, resultType)) {
417
413
return std::nullopt;
418
414
}
@@ -421,6 +417,11 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
421
417
return std::nullopt;
422
418
}
423
419
420
+ auto &diags = ctx.Diags ;
421
+ auto returnTypeRepr = afd->getResultTypeRepr ();
422
+ auto returnLoc = returnTypeRepr ? returnTypeRepr->getLoc ()
423
+ : afd->getLoc (/* SerializedOK */ false );
424
+
424
425
auto *cd = dyn_cast<ConstructorDecl>(afd);
425
426
if (cd && cd->isImplicit ()) {
426
427
if (cd->getParameters ()->size () == 0 ) {
@@ -438,7 +439,7 @@ LifetimeDependenceInfo::infer(AbstractFunctionDecl *afd, Type resultType) {
438
439
auto selfOwnership = afd->getImplicitSelfDecl ()->getValueOwnership ();
439
440
if (!isLifetimeDependenceCompatibleWithOwnership (kind, selfOwnership,
440
441
afd)) {
441
- diags.diagnose (afd-> getLoc () ,
442
+ diags.diagnose (returnLoc ,
442
443
diag::lifetime_dependence_invalid_self_ownership);
443
444
return std::nullopt;
444
445
}
0 commit comments