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

Document swift compiler bug in @DependencyClient. #189

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,25 @@ dependency from the implementation (see
<doc:LivePreviewTest#Separating-interface-and-implementation> for more information). But now there
is no need to maintain that code as it is automatically provided for you by the macro.

> Warning: Due to a [bug in the Swift compiler](https://github.com/apple/swift/issues/71070),
> endpoints that are not throwing will not emit a test failure when invoked. This applies to
> dependencies with endpoints like this:
>
> ```swift
> @DependencyClient
> struct NumberFetcher {
> var get: () async -> Int = { 42 }
> }
> ```
>
> The workaround is to invoke `XCTFail` directly in the closure:
>
> ```swift
> @DependencyClient
> struct NumberFetcher {
> var get: () async -> Int = { XCTFail("\(Self.self).get"); return 42 }
> }
> ```

[designing-deps]: https://www.pointfree.co/collections/dependencies
[xctest-dynamic-overlay-gh]: https://github.com/pointfreeco/xctest-dynamic-overlay
20 changes: 20 additions & 0 deletions Sources/DependenciesMacros/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@
/// and does not need to signify a real value. For example, if the endpoint returns a boolean, you
/// can return `false`, or if it returns an array, you can return `[]`.`
///
/// > Warning: Due to a [bug in the Swift compiler](https://github.com/apple/swift/issues/71070),
/// > endpoints that are not throwing will not emit a test failure when invoked. This applies to
/// > dependencies with endpoints like this:
/// >
/// > ```swift
/// > @DependencyClient
/// > struct NumberFetcher {
/// > var get: () async -> Int = { 42 }
/// > }
/// > ```
/// >
/// > The workaround is to invoke `XCTFail` directly in the closure:
/// >
/// > ```swift
/// > @DependencyClient
/// > struct NumberFetcher {
/// > var get: () async -> Int = { XCTFail("\(Self.self).get"); return 42 }
/// > }
/// > ```
///
/// [designing-dependencies]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/designingdependencies
/// [separating-interface-implementation]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/livepreviewtest#Separating-interface-and-implementation
@attached(member, names: named(init))
Expand Down
Loading