-
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.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
per SE-434, subclassing a non-Sendable, nonisolated class with a global actor isolated subclass should be rejected:
We propose that:
[snip...]
- A global-actor-isolated subclass of a non-isolated, non-Sendable class is allowed, but it must be non-Sendable.
today it is not, which is a data race safety hole.
Reproduction
open class NonSendable {
var superProp = ""
func test() {}
}
@MainActor
final class IsolatedSubclass: NonSendable, Sendable { // accepted but should not be
func trySendableCapture() {
for _ in 0...100 {
Task.detached {
self.superProp += "1"
print("prop: ", self.superProp)
}
}
}
}
@main
enum App {
static func main() async {
let iso = IsolatedSubclass()
iso.trySendableCapture()
try? await Task.sleep(for: .seconds(2))
}
}Expected behavior
the Sendable, global actor isolated subclass should be rejected by the compiler.
Environment
Swift version 6.2 (swift-6.2-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional information
came up when thinking about this: https://forums.swift.org/t/pitch-sendable-conformance-for-suppressing-sendable-inference/83288/40
godbolt: https://godbolt.org/z/sqz94q3ea
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.triage neededThis issue needs more specific labelsThis issue needs more specific labels