swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.49k stars 10.35k forks source link

`nonisolated` applied to `@propertyWrapper`-wrapped property does not propagate to `projectedValue` in `deinit` #59380

Open b8591340 opened 2 years ago

b8591340 commented 2 years ago
import Foundation

@propertyWrapper struct Wrapper {
    var   wrappedValue: Int { .zero }
    var projectedValue: Int { .max }
}

@MainActor
class Sample {
    @Wrapper nonisolated var value

    deinit {
        print (value)
        print($value)
    }
}
error: property '$value' isolated to global actor 'MainActor' can not be referenced from this synchronous context
        print($value)
              ^`

Starting from Swift 5.7 (Xcode 14 beta 1), only with -Xfrontend -warn-concurrency.

theblixguy commented 2 years ago

Looking at the code, it seems like we need to add an implicit NonIsolatedAttr to the projectedValue (probably when synthesising it). We don’t do it for the value property because we’re simply synthesising accessors for it and not creating a separate property, that’s why it doesn’t trigger an error (since the property already has the attribute).