swift icon indicating copy to clipboard operation
swift copied to clipboard

SIGABRT on calling a protocol method that is implemented in a global actor-tied class

Open crontab opened this issue 5 months ago • 0 comments

Description

Swift can crash at run time and print “Incorrect actor executor assumption” in the following situation (see code snippet below).

If I either remove the protocol, i.e. use the class directly, or if I use a normal actor instead of a global one, the app doesn't crash. Also, the crash only happens when compiled in Swift 6 mode.

Reproduction

protocol P {
	var key: String { get }
}

@globalActor
actor GA {
	static var shared = GA()
}

@GA
class A: P {
	let key: String = "SomeKey"
}

let p: P = A()
print(p.key) // <- SIGABRT here

Stack dump

(This happens in Xcode, sorry I don't know where to take the stack dump from. The thread view in Xcode doesn't show much except the call site of the function where this happens.)

Expected behavior

Shouldn't crash, or otherwise detect concurrency problem at compile time.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx14.0

Additional information

No response

crontab avatar Sep 23 '24 11:09 crontab