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

#isolation within a lazy var initializer should evaluate to the instance's static isolation #79060

Open
mattmassicotte opened this issue Jan 30, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@mattmassicotte
Copy link
Contributor

Description

I've discovered that #isolation always returns nil for lazy var initializers. Today, all of these print nil.

Reproduction

func captureIsolation(isolation: isolated (any Actor)? = #isolation) -> Int {
	print(isolation)

	return 1
}

class NoIsolation {
	// here's nil and that makes sense
	lazy var value = captureIsolation()
}

actor MyActor {
	// I think #isolation should evaluate to self here
	lazy var value = captureIsolation()
}

@MainActor
class GlobalClass {
	// I think #isolation should evaluate to MainActor.shared here
	lazy var value = captureIsolation()
}

_ = NoIsolation().value
_ = await MyActor().value
_ = GlobalClass().value

Expected behavior

I think the static isolation should always be knowable in the actor and global actor situations, shouldn't it?

Environment

Apple Swift version 6.1-dev (LLVM a321a98f4e5b06a, Swift 7a0a6e7)
Target: arm64-apple-macosx15.0

Additional information

No response

@mattmassicotte mattmassicotte added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant