Skip to content

Undesired isolation inference for implementations of implicitly nonisolated(nonsending) requirements #86944

@AnthonyLatsis

Description

@AnthonyLatsis

Description

nonisolated(nonsending) is synonymous to nonisolated when NonisolatedNonsendingByDefault is enabled. However, when considering the implicit isolation of an associated protocol requirement for the purpose of inferring the isolation of a method, isolation inference treats them differently. Implicit nonisolated (modelled as "unspecified" isolation) loses to a global-actor-isolated type context, whereas implicit nonisolated(nonsending) wins.

Reproduction

// -enable-upcoming-feature NonisolatedNonsendingByDefault
protocol P {
  /*nonisolated(nonsending)*/ func foo() async
}

@MainActor struct S: P {
  /*nonisolated(nonsending)*/ func foo() async {}
}
protocol P {
  /*nonisolated*/ func foo() async
}

@MainActor struct S: P {
  /*@MainActor*/ func foo() async {}
}

Expected behavior

@MainActor wins in both cases.

Environment

Swift version 6.3-dev (520471c)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    actorFeature → concurrency: `actor` declarationscompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresnonisolated(nonsending)Feature → modifiers: The "nonisolated(nonsending)" modifierswift 6.3type checkerArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions