Closed
Description
Previous ID | SR-15745 |
Radar | rdar://90354322 |
Original Reporter | @CharlesJS |
Type | Bug |
Environment
$ swiftc --version
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: x86_64-apple-macosx12.0
Additional Detail from JIRA
Votes | 3 |
Component/s | swift |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: 581829c2432961ebf61e130142bf32e5
Issue Description:
This compiles, and I'm pretty sure it shouldn't:
import Dispatch
func someFunctionThatDoesWhoKnowsWhatWithThis(closure: @escaping () -> ()) {
DispatchQueue.main.async { closure() }
}
class SomeClass {}
actor Foo {
var bar = SomeClass()
func setBar(_ bar: SomeClass) { self.bar = bar }
func baz() {
someFunctionThatDoesWhoKnowsWhatWithThis {
self.setBar(.init()) // shouldn't this require an `await`?
}
}
}
The code inside the `@escaping` closure is no longer running inside the actor's context, so it seems like it shouldn't be able to call the actor's methods without an `await`, and that this is therefore a bug.
Forum thread with related discussion: https://forums.swift.org/t/calling-escaping-closure-from-actor-context-why-dont-i-need-await-here/51029
Metadata
Metadata
Assignees
Labels
Feature → concurrency: asynchronous function aka the async/await patternA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: umbrella label for concurrency language featuresBug: Diagnostics Quality of ImplementationResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error