@@ -167,7 +167,8 @@ extension __ExpectationContext {
167
167
///
168
168
/// This function helps overloads of `callAsFunction(_:_:)` disambiguate
169
169
/// themselves and avoid accidental recursion.
170
- @usableFromInline func captureValue< T> ( _ value: T , _ id: __ExpressionID ) -> T {
170
+ @usableFromInline func captureValue< T> ( _ value: consuming T , _ id: __ExpressionID ) -> T {
171
+ let value = copy value
171
172
runtimeValues [ id] = { Expression . Value ( reflecting: value) }
172
173
return value
173
174
}
@@ -185,7 +186,7 @@ extension __ExpectationContext {
185
186
/// - Warning: This function is used to implement the `#expect()` and
186
187
/// `#require()` macros. Do not call it directly.
187
188
@_disfavoredOverload
188
- @inlinable public func callAsFunction< T> ( _ value: T , _ id: __ExpressionID ) -> T {
189
+ @inlinable public func callAsFunction< T> ( _ value: consuming T , _ id: __ExpressionID ) -> T {
189
190
captureValue ( value, id)
190
191
}
191
192
@@ -275,12 +276,14 @@ extension __ExpectationContext {
275
276
@inlinable public func __cmp< T, U> (
276
277
_ op: ( T , U ) throws -> Bool ,
277
278
_ opID: __ExpressionID ,
278
- _ lhs: T ,
279
+ _ lhs: borrowing T ,
279
280
_ lhsID: __ExpressionID ,
280
- _ rhs: U ,
281
+ _ rhs: borrowing U ,
281
282
_ rhsID: __ExpressionID
282
283
) rethrows -> Bool {
283
- try captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
284
+ let lhs = copy lhs
285
+ let rhs = copy rhs
286
+ return try captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
284
287
}
285
288
286
289
/// Compare two bidirectional collections using `==` or `!=`.
@@ -293,11 +296,13 @@ extension __ExpectationContext {
293
296
public func __cmp< C> (
294
297
_ op: ( C , C ) -> Bool ,
295
298
_ opID: __ExpressionID ,
296
- _ lhs: C ,
299
+ _ lhs: borrowing C ,
297
300
_ lhsID: __ExpressionID ,
298
- _ rhs: C ,
301
+ _ rhs: borrowing C ,
299
302
_ rhsID: __ExpressionID
300
303
) -> Bool where C: BidirectionalCollection , C. Element: Equatable {
304
+ let lhs = copy lhs
305
+ let rhs = copy rhs
301
306
let result = captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
302
307
303
308
if !result {
@@ -318,12 +323,14 @@ extension __ExpectationContext {
318
323
@inlinable public func __cmp< R> (
319
324
_ op: ( R , R ) -> Bool ,
320
325
_ opID: __ExpressionID ,
321
- _ lhs: R ,
326
+ _ lhs: borrowing R ,
322
327
_ lhsID: __ExpressionID ,
323
- _ rhs: R ,
328
+ _ rhs: borrowing R ,
324
329
_ rhsID: __ExpressionID
325
330
) -> Bool where R: RangeExpression & BidirectionalCollection , R. Element: Equatable {
326
- captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
331
+ let lhs = copy lhs
332
+ let rhs = copy rhs
333
+ return captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
327
334
}
328
335
329
336
/// Compare two strings using `==` or `!=`.
@@ -337,11 +344,13 @@ extension __ExpectationContext {
337
344
public func __cmp< S> (
338
345
_ op: ( S , S ) -> Bool ,
339
346
_ opID: __ExpressionID ,
340
- _ lhs: S ,
347
+ _ lhs: borrowing S ,
341
348
_ lhsID: __ExpressionID ,
342
- _ rhs: S ,
349
+ _ rhs: borrowing S ,
343
350
_ rhsID: __ExpressionID
344
351
) -> Bool where S: StringProtocol {
352
+ let lhs = copy lhs
353
+ let rhs = copy rhs
345
354
let result = captureValue ( op ( captureValue ( lhs, lhsID) , captureValue ( rhs, rhsID) ) , opID)
346
355
347
356
if !result {
@@ -392,7 +401,8 @@ extension __ExpectationContext {
392
401
///
393
402
/// - Warning: This function is used to implement the `#expect()` and
394
403
/// `#require()` macros. Do not call it directly.
395
- @inlinable public func __as< T, U> ( _ value: T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
404
+ @inlinable public func __as< T, U> ( _ value: consuming T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
405
+ let value = copy value
396
406
let result = captureValue ( value, valueID) as? U
397
407
398
408
if result == nil {
@@ -421,7 +431,8 @@ extension __ExpectationContext {
421
431
///
422
432
/// - Warning: This function is used to implement the `#expect()` and
423
433
/// `#require()` macros. Do not call it directly.
424
- @inlinable public func __is< T, U> ( _ value: T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> Bool {
434
+ @inlinable public func __is< T, U> ( _ value: borrowing T , _ valueID: __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> Bool {
435
+ let value = copy value
425
436
let result = captureValue ( value, valueID) is U
426
437
427
438
if !result {
0 commit comments