Skip to content

Despite the sending return, I cannot satisfy protocol with a sending return #76710

Closed
@mattmassicotte

Description

@mattmassicotte

Description

I thought for sure this was going to work, but somewhat similar to #76677, it doesn't look like the sending is being taken into account here. The Sendability of the return type should not matter in this case, should it?

Reproduction

final class DataModel {
	let name: String

	init(name: String) {
		self.name = name
	}
}

protocol DataStoring {
	func loadModel() async -> sending DataModel
}

@MainActor
final class DataStore: DataStoring {
	func loadModel() async -> sending DataModel {
	// error: non-sendable type 'DataModel' returned by main actor-isolated instance method 'loadModel()' satisfying protocol requirement cannot cross actor boundary
		DataModel(name: "foo")
	}
}

Expected behavior

I'd expect this to compile without error.

Environment

Apple Swift version 6.0.2-dev (LLVM 43d73cb0cc589f7, Swift aaa632c)
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 featuresconformancesFeature → protocol: protocol conformancesdeclarationsFeature: declarationstype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions