Var of Atomic type is not an error?

I've downloaded latest nightly toolchain and this code compiles without error:

@available(macOS 9999, *)
class Test {
    private var x = Atomic<Int>(1)

    func test() {
        x.store(2, ordering: .relaxed)
    }
}

My understanding of SE-0410 is that this should be an error?

1 Like

The behavior is hidden behind the StaticExclusiveOnly experimental feature flag which enables a new @_staticExclusiveOnly attribute which basically results in the behavior you're expecting, when applied to non-copyable types like the new Atomic type.

Try declaring that in your Package.swift or adding it like -enable-experimental-feature StaticExclusiveOnly to the swift invocation when using CLI.

2 Likes

I've put a PR together to mention this behavior in the proposal itself: [0410-atomics] Mention the 'let–only' behavior of `Atomic` is gated behind a flag by MahdiBM · Pull Request #2306 · apple/swift-evolution · GitHub

1 Like

The intent is for the checking to ultimately be enabled unconditionally, so at some point we should enable the experimental feature flag.

2 Likes

+1 [0410-atomics] Mention the 'let–only' behavior of `Atomic` is gated behind a flag by MahdiBM · Pull Request #2306 · apple/swift-evolution · GitHub

1 Like

This is incorrectly checking the client's experimental features when determining if something should be a let or not. Right, the intent was that you cannot utter @_staticExclusiveOnly unless you have the flag on. I'll make a patch here real quick.

7 Likes
3 Likes