Skip to content

Initialize endpoints through storage instead of computed property - #470

Merged
stephencelis merged 3 commits into
mainfrom
init-closures-last
Aug 24, 2026
Merged

Initialize endpoints through storage instead of computed property#470
stephencelis merged 3 commits into
mainfrom
init-closures-last

Conversation

@mbrandonw

Copy link
Copy Markdown
Member

Right now something like this does not compile:

@DependencyClient private struct ClientWithClosuresBeforeNonClosures {
  var endpoint: () async throws -> Int  // 🛑 'self' used before all stored properties are initialized
  var identifier: String
}

The reason is that @DependencyEndpoint is applied to endpoint and not identifier, and that macro turns the stored property into a stored+computed property combo. The initializer sets only the computed property, not the stored. We used to work around this with an init accessor, but that caused other problems (#355). So instead we can just set the underscored stored property in the initializer.

@mbrandonw
mbrandonw requested a review from stephencelis August 22, 2026 17:11
@mbrandonw mbrandonw changed the title Initialize closures last. Initialize endpoints through storage instead of computed property Aug 22, 2026
@stephencelis
stephencelis merged commit b0d44b3 into main Aug 24, 2026
7 checks passed
@stephencelis
stephencelis deleted the init-closures-last branch August 24, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants