mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This is done by diagnosing captures of `self` in escaping `sending` or `@Sendable` closures inside a deinit, which almost certainly means `self` will outlive deinit at runtime, which is a fatal error. This is a common mistake to make when creating isolated tasks inside nonisolated deinits to workaround the lack of synchrnous isolated deinits in Swift 6.
38 lines
982 B
Swift
38 lines
982 B
Swift
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -disable-availability-checking
|
|
|
|
@MainActor
|
|
class C {
|
|
let x: Int = 0
|
|
|
|
deinit {
|
|
// expected-warning@+1 {{capture of 'self' in a closure that outlives deinit; this is an error in the Swift 6 language mode}}
|
|
Task { @MainActor in
|
|
_ = self
|
|
}
|
|
|
|
// expected-warning@+1 {{capture of 'self' in a closure that outlives deinit; this is an error in the Swift 6 language mode}}
|
|
Task {
|
|
_ = x
|
|
}
|
|
}
|
|
}
|
|
|
|
func enqueueSomewhereElse(_ closure: @escaping @Sendable () -> Void) {}
|
|
|
|
@MainActor
|
|
class C2 {
|
|
let x: Int = 0
|
|
|
|
deinit {
|
|
// expected-warning@+1 {{capture of 'self' in a closure that outlives deinit; this is an error in the Swift 6 language mode}}
|
|
enqueueSomewhereElse {
|
|
_ = self
|
|
}
|
|
|
|
// expected-warning@+1 {{capture of 'self' in a closure that outlives deinit; this is an error in the Swift 6 language mode}}
|
|
enqueueSomewhereElse {
|
|
_ = self.x
|
|
}
|
|
}
|
|
}
|