Skip to content

Calling an isolated function in a non-Sendable closure shouldn't be sending self #77067

Closed
@mattmassicotte

Description

@mattmassicotte

Description

I'm not sure how it's possible that self could be sent in this situation. The closures involved are not @Sendable, so the isolation should never change.

- error: sending 'self' risks causing data races
- note: 'isolation'-isolated 'self' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses

Reproduction

class MyClass {
	var handler: (@escaping () -> Void) -> Void = { _ in }

	func doThing(isolation: isolated (any Actor)?) {
		handler {
			// error: sending 'self' risks causing data races
			self.doOtherThing(isolation: isolation)
		}
	}

	func doOtherThing(isolation: isolated (any Actor)?) {
	}
}

Expected behavior

I would expect this to compile error-free.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions