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

actor's lazy var with closure expression results in isolation error #79075

Open
mattmassicotte opened this issue Jan 31, 2025 · 1 comment
Open
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'm honestly not sure I understand exactly what is going on here. And it is possible this is related to #79060

I would expect this code to compile. I also think the diagnostic message could use a little work, but I cannot come up with another scenario that produces the same error.

Reproduction

func doStuff(work: () async -> Int?) -> Int {
	0
}

actor MyActor {
	func action() {
	}

	// error: Actor-isolated default value in a actor-isolated context
	private lazy var bad = doStuff(work: {
		self.action()

		return nil
	})

	private lazy var good = runDoStuff()

	func runDoStuff() -> Int {
		doStuff(work: {
			self.action()

			return nil
		})
	}
}

Expected behavior

It seems to me like these two things should be equivalent, no?

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 31, 2025
@mattmassicotte
Copy link
Contributor Author

Figured something out for the diagnostic: #79077

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