Skip to content

[SR-16052] Compiler error when referencing global actor isolated value from non-isolated initializer with property wrapper #58313

@swift-ci

Description

@swift-ci
Previous ID SR-16052
Radar None
Original Reporter StarLard (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 13.3

Swift 5.6

Additional Detail from JIRA
Votes 0
Component/s Compiler, swift
Labels Bug, Concurrency, PropertyWrappers
Assignee None
Priority Medium

md5: f522783fd58bc1635562f6ecf2e3eca5

Issue Description:

Compiler produces an actor isolation violation error when referencing a wrapped property from a global actor isolated class' init or deinit methods. Using the long-form declaration of the property wrapper or forgoing the property wrapper does not trigger the violation. Using an actor type instead of a global actor isolated class also does not reproduce this error.

Error Reproduction Example:

@propertyWrapper struct Wrapped<Value> {
    var wrappedValue: Value

    init(wrappedValue: Value) {
        self.wrappedValue = wrappedValue
    }
}

@MainActor
class Example {
    var notWrappedValue: Bool = true
    
    @Wrapped
    var wrappedValue: Bool = true
    
    var wrappedValueLong: Wrapped<Bool> = Wrapped(wrappedValue: true)
    
    nonisolated init() {
        _ = self.notWrappedValue // Ok
        _ = self.wrappedValueLong // Ok
        _ = self.wrappedValue // Error: Property 'value' isolated to global actor 'MainActor' can not be referenced from a non-isolated synchronous context
    }
    
    deinit {
        _ = self.notWrappedValue // Ok
        _ = self.wrappedValueLong // Ok
        _ = self.wrappedValue // Error: Property 'value' isolated to global actor 'MainActor' can not be referenced from this synchronous context
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    actorFeature → concurrency: `actor` declarationsactor isolationFeature → concurrency: Actor isolationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresproperty wrappersFeature: property wrappers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions