@@ -162,6 +162,22 @@ extension __ExpectationContext: Sendable {}
162162// MARK: - Expression capturing
163163
164164extension __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+
165181 /// Capture information about a value for use if the expectation currently
166182 /// being evaluated fails.
167183 ///
@@ -464,7 +480,7 @@ extension __ExpectationContext {
464480 /// - Warning: This function is used to implement the `#expect()` and
465481 /// `#require()` macros. Do not call it directly.
466482 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
468484 P2 ( bitPattern: Int ( bitPattern: value) )
469485 }
470486 }
@@ -495,7 +511,7 @@ extension __ExpectationContext {
495511 /// `#require()` macros. Do not call it directly.
496512 public mutating func callAsFunction< P> ( _ value: String , _ id: __ExpressionID ) -> P where P: _Pointer {
497513 // Perform the normal value capture.
498- let value = self ( value as String , id)
514+ let value = _captureValue ( value, id)
499515
500516 // Create a C string copy of `value`.
501517 let valueCString = value. withCString { value in
@@ -530,7 +546,7 @@ extension __ExpectationContext {
530546 /// - Warning: This function is used to implement the `#expect()` and
531547 /// `#require()` macros. Do not call it directly.
532548 public mutating func callAsFunction( _ value: String ? , _ id: __ExpressionID ) -> String ! {
533- self ( value as String ? , id)
549+ _captureValue ( value, id)
534550 }
535551}
536552#endif
0 commit comments