Skip to content

Inherited protocol with Equatable doesn't infer MainActor #83610

@ricky-sharp

Description

@ricky-sharp

Description

When using default actor isolation of MainActor, having a protocol which conforms to Equatable forces workarounds on conforming types.

Note that the majority of cases were already fixed (see: #82384)

So perhaps this is something unique to Equatable.

Reproduction

protocol P1: Equatable { }

struct S1: P1 { }
// Error: Conformance of 'S1' to protocol 'P1' crosses into main actor-isolated code an can cause data races

struct S1Workaround: @MainActor P1 { }	// OK

// Another potential workaround if `Equatable` conformance can be moved to the conforming type.
protocol P2 { }

struct S2: Equatable, P2 { }	// OK

Expected behavior

Similar to what was fixed previously (example below), it should be possible to have a protocol conform to Equatable without requiring conforming types to have to specify @MainActor

// This used to fail with the same error, but has been addressed
protocol P1: Codable { }

struct S1: P1 { }

Environment

6.2 (swiftlang-6.2.0.16.14 clang-1700.3.16.4)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions