Skip to content

nonisolated property wrappers #76725

Open
@mattmassicotte

Description

@mattmassicotte

Motivation

This isn't an area I understand very well. But it seems like nonisolated property wrappers should be possible if the underlying wrapper type is Sendable.

@propertyWrapper
struct Wrapped<T: Sendable>: Sendable {
	var wrappedValue: T

	init(wrappedValue: T) {
		self.wrappedValue = wrappedValue
	}
}

actor MyActor {
	// if you can write this...
	nonisolated var computedValue: Int {
		get {
			0
		}
		set {
			// ... even if it tricky to implement
		}
	}

	// shouldn't you be able to write this
	// if the wrapper is Sendable?
	@Wrapped nonisolated var wrappedValue: Int = 0
}

Proposed solution

I think this code should be accepted. As is, it produces an error:

error: 'nonisolated' is not supported on properties with property wrappers

Alternatives considered

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    actor isolationFeature → concurrency: Actor isolationcompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresfeatureA feature request or implementationproperty wrappersFeature: property wrappersswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions