Skip to content

Commit f5f64da

Browse files
authored
Document swift compiler bug in @DependencyClient. (#189)
1 parent 09e49dd commit f5f64da

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Sources/Dependencies/Documentation.docc/Articles/DesigningDependencies.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,25 @@ dependency from the implementation (see
229229
<doc:LivePreviewTest#Separating-interface-and-implementation> for more information). But now there
230230
is no need to maintain that code as it is automatically provided for you by the macro.
231231

232+
> Warning: Due to a [bug in the Swift compiler](https://github.com/apple/swift/issues/71070),
233+
> endpoints that are not throwing will not emit a test failure when invoked. This applies to
234+
> dependencies with endpoints like this:
235+
>
236+
> ```swift
237+
> @DependencyClient
238+
> struct NumberFetcher {
239+
> var get: () async -> Int = { 42 }
240+
> }
241+
> ```
242+
>
243+
> The workaround is to invoke `XCTFail` directly in the closure:
244+
>
245+
> ```swift
246+
> @DependencyClient
247+
> struct NumberFetcher {
248+
> var get: () async -> Int = { XCTFail("\(Self.self).get"); return 42 }
249+
> }
250+
> ```
251+
232252
[designing-deps]: https://www.pointfree.co/collections/dependencies
233253
[xctest-dynamic-overlay-gh]: http://github.com/pointfreeco/xctest-dynamic-overlay

Sources/DependenciesMacros/Macros.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@
111111
/// and does not need to signify a real value. For example, if the endpoint returns a boolean, you
112112
/// can return `false`, or if it returns an array, you can return `[]`.`
113113
///
114+
/// > Warning: Due to a [bug in the Swift compiler](https://github.com/apple/swift/issues/71070),
115+
/// > endpoints that are not throwing will not emit a test failure when invoked. This applies to
116+
/// > dependencies with endpoints like this:
117+
/// >
118+
/// > ```swift
119+
/// > @DependencyClient
120+
/// > struct NumberFetcher {
121+
/// > var get: () async -> Int = { 42 }
122+
/// > }
123+
/// > ```
124+
/// >
125+
/// > The workaround is to invoke `XCTFail` directly in the closure:
126+
/// >
127+
/// > ```swift
128+
/// > @DependencyClient
129+
/// > struct NumberFetcher {
130+
/// > var get: () async -> Int = { XCTFail("\(Self.self).get"); return 42 }
131+
/// > }
132+
/// > ```
133+
///
114134
/// [designing-dependencies]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/designingdependencies
115135
/// [separating-interface-implementation]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/livepreviewtest#Separating-interface-and-implementation
116136
@attached(member, names: named(init))

0 commit comments

Comments
 (0)