Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment within a non-isolated init should be equivalent to a default expression #78809

Open
mattmassicotte opened this issue Jan 22, 2025 · 0 comments
Labels
feature A feature request or implementation triage needed This issue needs more specific labels

Comments

@mattmassicotte
Copy link
Contributor

Motivation

I cannot see how the assignment here could actually result in a race or be meaningfully-different than using a default value expression.

class NonSendable {}

@MainActor
struct AssignsInInit {
	var param: Int
	var value: NonSendable

	nonisolated init(param: Int, value: NonSendable) {
		self.param = param
		self.value = value // error: main actor-isolated property 'value' can not be mutated from a nonisolated context
	}
}

@MainActor
struct AssignsViaDefaultExpression {
	var param: Int
	var value = NonSendable()

	nonisolated init(param: Int, value: NonSendable) {
		self.param = param
	}
}

Proposed solution

I think this code should compile error-free.

Alternatives considered

No response

Additional information

No response

@mattmassicotte mattmassicotte added feature A feature request or implementation triage needed This issue needs more specific labels labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant