-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featurescrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during executionBug → crash: Swift code crashed during execution
Description
Description
the combination of NonisolatedNonsendingByDefault, default MainActor isolation, and the swift 5 language mode seems like it can lead to function conversion miscompilation in which the implicit nonisolated(nonsending) isolation parameter is incorrectly passed as an explicit parameter.
Reproduction
/*
built with:
xcrun swiftc \
-enable-upcoming-feature NonisolatedNonsendingByDefault \
-default-isolation MainActor \
-swift-version 5 \
-parse-as-library
*/
struct S {
var action: (AnyObject) async -> Void
init(action: @escaping (AnyObject) -> Void) {
self.action = action
}
}
@main
enum App {
static func main() async {
let s = S { print($0) }
await s.action(42 as AnyObject) // prints: 'Swift.MainActor'
}
}changing the param from AnyObject to other types typically results in runtime crashes.
Expected behavior
the code should correctly perform the necessary function conversions without mixing up the parameters.
Environment
Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx26.0
Additional information
issue was originally reported and discussed here: https://forums.swift.org/t/exc-bad-access-with-escaping-closure-and-task/83989
godbolt: https://swift.godbolt.org/z/8cdd8zszo
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featurescrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during executionBug → crash: Swift code crashed during execution