Skip to content

Improve @DependencyEntry diagnostics - #460

Open
stephencelis wants to merge 4 commits into
mainfrom
main-actor-check
Open

Improve @DependencyEntry diagnostics#460
stephencelis wants to merge 4 commits into
mainfrom
main-actor-check

Conversation

@stephencelis

Copy link
Copy Markdown
Member

In the spirit of the checks we've added elsewhere, let's better surface a few error messages that are currently buried in the macro.

Default MainActor isolation

We currently allow this to compile in modules with default MainActor isolation:

extension DependencyValues {
  @DependencyEntry var client = Client()
}

This produces a non-sendable \.client key path because it's bound to the main actor, which fails only later when you try to use it:

@Dependency(\.client) var client  🛑

We can instead bury a default isolation check directly in the macro and surface it early:

image

Non-sendable dependencies

Dependencies must be sendable but currently if you try do:

extension DependencyValues {
  @DependencyEntry var nonSendable = NS()
}

The failure is buried in the macro expansion. Let's surface it instead:

image

Non-matching types

It's possible to invoke @DependencyEntry with mismatched types, especially if you forget to specify any Client as an existential. This produces several errors all buried in the expansion, but we can surface these as well:

image

@stephencelis
stephencelis requested a review from mbrandonw August 1, 2026 02:07
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.

1 participant