Skip to content

Confusing error on cross-module access of isolated state #76909

Open
@AnthonyLatsis

Description

@AnthonyLatsis

Description

The message says "can not be mutated on a nonisolated actor instance" when the mutation is in fact performed on an instance of an isolated struct.

Reproduction

var s = S()
s.x += 0 // okay
// expected-error@+1 {{main actor-isolated property 'y' can not be mutated on a nonisolated actor instance}}
s.y += 1

Expected behavior

The part of the message at issue is chosen from a list of options:

ERROR(actor_isolated_non_self_reference,none,
"%4 %kind0 can not be "
"%select{referenced|mutated|used 'inout'}1 "
"%select{from outside the actor|on a different actor instance|"
"on a nonisolated actor instance|"
"from a Sendable function|from a Sendable closure|"
"from an 'async let' initializer|from global actor %3|"
"from the main actor|from a nonisolated context|"
"from a nonisolated autoclosure}2",

The correct option in this case appears to be "from a nonisolated context".

Environment

Swift version 6.1-dev (Swift 66d4cd1)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    actor isolationFeature → concurrency: Actor isolationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresdiagnostics QoIBug: Diagnostics Quality of Implementationmultiple modulesFlag: An issue whose reproduction requires multiple modulesswift 6.1type checkerArea → compiler: Semantic analysis

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions