Fix deserialization assertion involving isolated conformances

(cherry picked from commit f09cdc2893)
This commit is contained in:
Doug Gregor
2025-04-10 08:01:26 -07:00
parent 65a7b189ba
commit 678ea3df35
4 changed files with 14 additions and 3 deletions

View File

@@ -7942,7 +7942,7 @@ ConformanceIsolationRequest::evaluate(Evaluator &evaluator, ProtocolConformance
return ActorIsolation::forNonisolated(false);
// If we are inferring isolated conformances and the conforming type is
// isolated to a global actor,
// isolated to a global actor, use the conforming type's isolation.
auto nominal = dc->getSelfNominalTypeDecl();
if (ctx.LangOpts.hasFeature(Feature::InferIsolatedConformances) &&
nominal) {

View File

@@ -1058,8 +1058,11 @@ ProtocolConformanceDeserializer::readNormalProtocolConformance(
auto globalActorType = globalActorTypeOrError.get();
TypeExpr *globalActorTypeExpr = nullptr;
if (globalActorType)
if (globalActorType) {
globalActorTypeExpr = TypeExpr::createImplicit(globalActorType, ctx);
rawOptions |=
static_cast<unsigned>(ProtocolConformanceFlags::GlobalActorIsolated);
}
auto conformance = ctx.getNormalConformance(
conformingType, proto, SourceLoc(), dc,

View File

@@ -8,3 +8,8 @@ public class MyClass { }
extension MyClass: @MainActor MyProtocol {
@MainActor public func f() { }
}
public protocol OtherProtocol {
}
extension MyClass: OtherProtocol { }

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -target %target-swift-5.1-abi-triple -swift-version 6 -o %t/def_isolated_conformance.swiftmodule %S/Inputs/def_isolated_conformance.swift
// RUN: %target-swift-frontend -emit-module -target %target-swift-5.1-abi-triple -swift-version 6 -o %t/def_isolated_conformance.swiftmodule %S/Inputs/def_isolated_conformance.swift -default-isolation=MainActor
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 6 %s -I %t
@@ -8,8 +8,11 @@
import def_isolated_conformance
func acceptMyProtocol(_: some MyProtocol) { }
func acceptOtherProtocol(_: some MyProtocol) { }
nonisolated func f(mc: MyClass) {
acceptMyProtocol(mc)
// expected-error@-1{{main actor-isolated conformance of 'MyClass' to 'MyProtocol' cannot be used in nonisolated context}}
acceptOtherProtocol(mc)
// expected-error@-1{{main actor-isolated conformance of 'MyClass' to 'MyProtocol' cannot be used in nonisolated context}}
}