@preconcurrency doesn't suppress static property concurrency warnings

I have a SwiftPM package with dependencies on Argument Parser and Swift Markdown.

Building in Swift 5.10 with strict concurrency enabled generates warnings in both frameworks, both about static properties.

For example:

struct SnapshotCommand: AsyncParsableCommand {
    
    static let configuration = CommandConfiguration(
        commandName: Help.Snapshot.commandName,
        abstract: Help.Snapshot.abstract,
        discussion: Help.Snapshot.discussion
    )
    ...
}

Generates the warning:

Static property 'configuration' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6

Adding @preconcurrency to the import statement does not seem to help.

I had thought that @preconcurrency was meant to allow types to be used as Sendable even if they are not marked as such in the imported module.

So my questions are:

  1. What is @preconcurrency supposed to do?
    (e.g. Is what I'm seeing a bug or am I misunderstanding what @preconcurrency does)

  2. Besides marking static variables like this as nonisolated(unsafe) is there any way to suppress the warnings while waiting for the dependencies to update for concurrency?

Thank you in advance for any insights.

3 Likes

This is a compiler bug. Adding a @preconcurrency import should suppress the global variable warning, because CommandConfiguration being Sendable would make this code safe.

The other way to suppress the warning until the dependency is updated is to add a retroactive @unchecked Sendable conformance to the specific type you're using:

extension CommandConfiguration: @unchecked Sendable {}

The compiler should issue a warning if the library later adds a Sendable conformance, or marks the Sendable conformance unavailable.

8 Likes

Thank you @hborla. It's unfortunate there's a bug but good to know @precondition should work in the future. (Also better to have this bug in 5.10 than in 6.0)

I'll think about adding the retroactive conformance as opposed to the nonisolated(unsafe). Receiving the warning once the dependency updates would be helpful.

1 Like