Inferring conformance to an already-isolated protocol

This really feels like a bug to me, but it’s hard to be 100% sure. I have InfersIsolatedConformances enabled.

nonisolated protocol A {
    func requirement()
}

@MainActor
protocol MainActorA: A {
}

@MainActor
// error: Conformance of 'MyType' to protocol 'MainActorA' crosses into main actor-isolated code and can cause data races
struct MyType: MainActorA {
    func requirement() {
    }
}

What I think is happening is, because MainActorA has added isolation, the compiler doesn’t think that an isolated conformance is necessary. But making it explicit works.

Is this expected?

1 Like

clarifying question: do you also have default main actor isolation enabled?

I was trying to construct a dialect-independent reproducer, but I guess I got mixed up.

Here’s the example that is closer to the real problem I ran into.

@MainActor protocol RefineCodable: Codable {
}

@MainActor
struct MyType: RefineCodable {
}

hmm, yeah seems likely to be a bug to me, or at least something that could be better explained in the diagnostic feedback. the fact that the initial repro does not occur without default main actor isolation is a further mystery... @Douglas_Gregor @hborla does this error make sense to either of you?

1 Like