FB14338964: Breaking - Incorrect Swift 6 Concurrency Errors in Swift 5 project
- Date: 2024-06-16
- Resolution: Open
- Area: Swift Compiler
- OS: macOS
- Type: Incorrect/Unexpected Behavior
- Keywords: swift, compiler, concurrency, error, warning
Description
Concurrency errors related to the Sendable protocol are produced in a project, although it is configured for Swift 5. This behavior is new in Xcode 16.0 beta 3 (16A5202i) and breaks the build. Previous beta versions were not affected.
I've attached an Xcode project showing the issues.
Error 1 - Using WebKit:
import WebKit
This produces the following error: Add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'WebKit'
Error 2 - Using @preconcurrency
@preconcurrency import WebKit
In a Swift 5 project, this produces the following error: '@preconcurrency' attribute on module 'WebKit' has no effect
Error 3 - Closures and Sendable
let test = NSTreeController()
[self.observer](http://self.observer/) = self.observe( \.description )
{
_, _ in print( test )
}
Capture of 'test' with non-sendable type 'NSTreeController' in a @Sendable closure; this is an error in the Swift 6 language mode
These issues make building a Swift 5 project impossible with Xcode 16.0 beta 3.
Files
This project has warnings-as-errors turned on. Switch the build setting and the warnings are just that - only warnings. This is correct behavior.
The project indeed has warnings-as-errors enabled. Disabling this is not a valid solution. Treating warnings as errors can be a requirement on some projects.
At least provide a way to turn these warnings in Swift 5 projects as a build setting.
Since there is a -warn-concurrency flag, please provide a -no-warn-concurrency or -disable-warn-concurrency so we can use them on specific files while keeping warning as errors on.