Description
Description
The following code crashes the compiler with Segmentation Fault 11.
actor MyActor {
private var task: Task<Void, Never>?
private var flag = false
func foo() {
task = Task { [weak self] in
guard !Task.isCancelled, let self = self else { return }
flag.toggle()
}
}
}
If we remove check for 'Task.isCancelled', the compiler doesn't crash, but the context inside the Task is not inherited from actor and we have compilation error:
Actor-isolated property 'flag' can not be mutated from a non-isolated context
Steps to reproduce
Try to compile the code above.
Expected behavior
Compiler doesn't crash, actor context is inherited in the task.
Environment
-
Swift compiler version info
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.1 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0 -
Xcode version info
Xcode 14.3
Build version 14E222a -
Deployment target: iOS 16.4 (doesn't matter)
Additional info
Seems like [weak self] capture breaks context inheritance from actor, and combination with 'Task.isCancelled' crashes the compiler.