@@ -162,6 +162,22 @@ extension __ExpectationContext: Sendable {}
162
162
// MARK: - Expression capturing
163
163
164
164
extension __ExpectationContext {
165
+ /// Capture information about a value for use if the expectation currently
166
+ /// being evaluated fails.
167
+ ///
168
+ /// - Parameters:
169
+ /// - value: The value to pass through.
170
+ /// - id: A value that uniquely identifies the represented expression in the
171
+ /// context of the expectation currently being evaluated.
172
+ ///
173
+ /// - Returns: `value`, verbatim.
174
+ ///
175
+ /// This function helps overloads of `callAsFunction(_:_:)` disambiguate
176
+ /// themselves and avoid accidental recursion.
177
+ private mutating func _captureValue< T> ( _ value: T , _ id: __ExpressionID ) -> T {
178
+ self ( value, id)
179
+ }
180
+
165
181
/// Capture information about a value for use if the expectation currently
166
182
/// being evaluated fails.
167
183
///
@@ -464,7 +480,7 @@ extension __ExpectationContext {
464
480
/// - Warning: This function is used to implement the `#expect()` and
465
481
/// `#require()` macros. Do not call it directly.
466
482
public mutating func callAsFunction< P1, P2> ( _ value: P1 ? , _ id: __ExpressionID ) -> P2 ! where P1: _Pointer , P2: _Pointer {
467
- self ( value as P1 ? , id) . flatMap { value in
483
+ _captureValue ( value, id) . flatMap { value in
468
484
P2 ( bitPattern: Int ( bitPattern: value) )
469
485
}
470
486
}
@@ -495,7 +511,7 @@ extension __ExpectationContext {
495
511
/// `#require()` macros. Do not call it directly.
496
512
public mutating func callAsFunction< P> ( _ value: String , _ id: __ExpressionID ) -> P where P: _Pointer {
497
513
// Perform the normal value capture.
498
- let value = self ( value as String , id)
514
+ let value = _captureValue ( value, id)
499
515
500
516
// Create a C string copy of `value`.
501
517
let valueCString = value. withCString { value in
@@ -530,7 +546,7 @@ extension __ExpectationContext {
530
546
/// - Warning: This function is used to implement the `#expect()` and
531
547
/// `#require()` macros. Do not call it directly.
532
548
public mutating func callAsFunction( _ value: String ? , _ id: __ExpressionID ) -> String ! {
533
- self ( value as String ? , id)
549
+ _captureValue ( value, id)
534
550
}
535
551
}
536
552
#endif
0 commit comments