@@ -5022,16 +5022,19 @@ static void diagnoseConformanceIsolationErrors(
50225022 if (potentialIsolation && potentialIsolation->isGlobalActor () &&
50235023 !conformance->isIsolated ()) {
50245024 bool isMainActor = false ;
5025- Type globalActorIsolation = potentialIsolation->getGlobalActor ();
5026- if (auto nominal = globalActorIsolation ->getAnyNominal ())
5025+ Type globalActorType = potentialIsolation->getGlobalActor ();
5026+ if (auto nominal = globalActorType ->getAnyNominal ())
50275027 isMainActor = nominal->isMainActor ();
50285028
5029- auto diag = ctx.Diags .diagnose (
5030- conformance->getProtocolNameLoc (),
5031- diag::note_isolate_conformance_to_global_actor, globalActorIsolation,
5032- isMainActor, globalActorIsolation.getString ());
5033- conformance->applyConformanceAttribute (
5034- diag, " @" + globalActorIsolation.getString ());
5029+ // Take permanent ownership of the string. The diagnostic may outlive this
5030+ // function call.
5031+ auto globalActorTypeStr = ctx.AllocateCopy (globalActorType.getString ());
5032+ auto diag =
5033+ ctx.Diags .diagnose (conformance->getProtocolNameLoc (),
5034+ diag::note_isolate_conformance_to_global_actor,
5035+ globalActorType, isMainActor, globalActorTypeStr);
5036+ conformance->applyConformanceAttribute (diag,
5037+ " @" + globalActorTypeStr.str ());
50355038 }
50365039
50375040 // If marking witnesses as 'nonisolated' could work, suggest that.
0 commit comments