@@ -269,12 +269,12 @@ extension __ExpectationContext {
269
269
/// - Warning: This function is used to implement the `#expect()` and
270
270
/// `#require()` macros. Do not call it directly.
271
271
public mutating func __cmp< T, U, R> (
272
+ _ op: ( T , U ) throws -> R ,
273
+ _ opID: __ExpressionID ,
272
274
_ lhs: T ,
273
275
_ lhsID: __ExpressionID ,
274
276
_ rhs: U ,
275
- _ rhsID: __ExpressionID ,
276
- _ op: ( T , U ) throws -> R ,
277
- _ opID: __ExpressionID
277
+ _ rhsID: __ExpressionID
278
278
) rethrows -> R {
279
279
try self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
280
280
}
@@ -287,12 +287,12 @@ extension __ExpectationContext {
287
287
/// - Warning: This function is used to implement the `#expect()` and
288
288
/// `#require()` macros. Do not call it directly.
289
289
public mutating func __cmp< C> (
290
+ _ op: ( C , C ) -> Bool ,
291
+ _ opID: __ExpressionID ,
290
292
_ lhs: C ,
291
293
_ lhsID: __ExpressionID ,
292
294
_ rhs: C ,
293
- _ rhsID: __ExpressionID ,
294
- _ op: ( C , C ) -> Bool ,
295
- _ opID: __ExpressionID
295
+ _ rhsID: __ExpressionID
296
296
) -> Bool where C: BidirectionalCollection , C. Element: Equatable {
297
297
let result = self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
298
298
@@ -309,17 +309,17 @@ extension __ExpectationContext {
309
309
///
310
310
/// This overload of `__cmp()` does _not_ perform a diffing operation on `lhs`
311
311
/// and `rhs`. Range expressions are not usefully diffable the way other kinds
312
- /// of collections are. ([139222774](rdar ://139222774 ))
312
+ /// of collections are. ([#639](https ://github.com/swiftlang/swift-testing/issues/639 ))
313
313
///
314
314
/// - Warning: This function is used to implement the `#expect()` and
315
315
/// `#require()` macros. Do not call it directly.
316
316
public mutating func __cmp< R> (
317
+ _ op: ( R , R ) -> Bool ,
318
+ _ opID: __ExpressionID ,
317
319
_ lhs: R ,
318
320
_ lhsID: __ExpressionID ,
319
321
_ rhs: R ,
320
- _ rhsID: __ExpressionID ,
321
- _ op: ( R , R ) -> Bool ,
322
- _ opID: __ExpressionID
322
+ _ rhsID: __ExpressionID
323
323
) -> Bool where R: RangeExpression & BidirectionalCollection , R. Element: Equatable {
324
324
self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
325
325
}
@@ -333,12 +333,12 @@ extension __ExpectationContext {
333
333
/// - Warning: This function is used to implement the `#expect()` and
334
334
/// `#require()` macros. Do not call it directly.
335
335
public mutating func __cmp< S> (
336
+ _ op: ( S , S ) -> Bool ,
337
+ _ opID: __ExpressionID ,
336
338
_ lhs: S ,
337
339
_ lhsID: __ExpressionID ,
338
340
_ rhs: S ,
339
- _ rhsID: __ExpressionID ,
340
- _ op: ( S , S ) -> Bool ,
341
- _ opID: __ExpressionID
341
+ _ rhsID: __ExpressionID
342
342
) -> Bool where S: StringProtocol {
343
343
let result = self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
344
344
@@ -376,9 +376,11 @@ extension __ExpectationContext {
376
376
///
377
377
/// - Parameters:
378
378
/// - value: The value to cast.
379
+ /// - valueID: A value that uniquely identifies the expression represented
380
+ /// by `value` in the context of the expectation being evaluated.
379
381
/// - type: The type to cast `value` to.
380
- /// - typeID: The ID chain of the `type` expression as emitted during
381
- /// expansion of the `#expect()` or `#require()` macro .
382
+ /// - valueID: A value that uniquely identifies the expression represented
383
+ /// by `type` in the context of the expectation being evaluated .
382
384
///
383
385
/// - Returns: The result of the expression `value as? type`.
384
386
///
@@ -388,12 +390,12 @@ extension __ExpectationContext {
388
390
///
389
391
/// - Warning: This function is used to implement the `#expect()` and
390
392
/// `#require()` macros. Do not call it directly.
391
- public mutating func __as< T, U> ( _ value: T , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
392
- let result = value as? U
393
+ public mutating func __as< T, U> ( _ value: T , _ valueID : __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> U ? {
394
+ let result = self ( value, valueID ) as? U
393
395
394
396
if result == nil {
395
397
let correctType = Swift . type ( of: value as Any )
396
- runtimeValues [ typeID ] = { Expression . Value ( reflecting : correctType) }
398
+ _ = self ( correctType, typeID )
397
399
}
398
400
399
401
return result
@@ -403,9 +405,11 @@ extension __ExpectationContext {
403
405
///
404
406
/// - Parameters:
405
407
/// - value: The value to cast.
408
+ /// - valueID: A value that uniquely identifies the expression represented
409
+ /// by `value` in the context of the expectation being evaluated.
406
410
/// - type: The type `value` is expected to be.
407
- /// - typeID: The ID chain of the `type` expression as emitted during
408
- /// expansion of the `#expect()` or `#require()` macro .
411
+ /// - valueID: A value that uniquely identifies the expression represented
412
+ /// by `type` in the context of the expectation being evaluated .
409
413
///
410
414
/// - Returns: The result of the expression `value as? type`.
411
415
///
@@ -415,12 +419,12 @@ extension __ExpectationContext {
415
419
///
416
420
/// - Warning: This function is used to implement the `#expect()` and
417
421
/// `#require()` macros. Do not call it directly.
418
- public mutating func __is< T, U> ( _ value: T , _ type: U . Type , _ typeID: __ExpressionID ) -> Bool {
419
- let result = value is U
422
+ public mutating func __is< T, U> ( _ value: T , _ valueID : __ExpressionID , _ type: U . Type , _ typeID: __ExpressionID ) -> Bool {
423
+ let result = self ( value, valueID ) is U
420
424
421
425
if !result {
422
426
let correctType = Swift . type ( of: value as Any )
423
- runtimeValues [ typeID ] = { Expression . Value ( reflecting : correctType) }
427
+ _ = self ( correctType, typeID )
424
428
}
425
429
426
430
return result
@@ -445,46 +449,9 @@ extension __ExpectationContext {
445
449
///
446
450
/// - Warning: This function is used to implement the `#expect()` and
447
451
/// `#require()` macros. Do not call it directly.
448
- public mutating func callAsFunction< P, T> ( _ value: P , _ id: __ExpressionID ) -> UnsafePointer < T > where P: _Pointer {
449
- self ( value as P ? , id) !
450
- }
451
-
452
- /// Convert some pointer to an immutable one and capture information about it
453
- /// for use if the expectation currently being evaluated fails.
454
- ///
455
- /// - Parameters:
456
- /// - value: The pointer to make immutable.
457
- /// - id: A value that uniquely identifies the represented expression in the
458
- /// context of the expectation currently being evaluated.
459
- ///
460
- /// - Returns: `value`, cast to an immutable pointer.
461
- ///
462
- /// This overload of `callAsFunction(_:_:)` handles the implicit conversions
463
- /// between various pointer types that are normally provided by the compiler.
464
- ///
465
- /// - Warning: This function is used to implement the `#expect()` and
466
- /// `#require()` macros. Do not call it directly.
467
- public mutating func callAsFunction< P, T> ( _ value: P ? , _ id: __ExpressionID ) -> UnsafePointer < T > ? where P: _Pointer {
468
- UnsafePointer ( bitPattern: Int ( bitPattern: self ( value, id) as P ? ) )
469
- }
470
-
471
- /// Convert some pointer to an immutable one and capture information about it
472
- /// for use if the expectation currently being evaluated fails.
473
- ///
474
- /// - Parameters:
475
- /// - value: The pointer to make immutable.
476
- /// - id: A value that uniquely identifies the represented expression in the
477
- /// context of the expectation currently being evaluated.
478
- ///
479
- /// - Returns: `value`, cast to an immutable pointer.
480
- ///
481
- /// This overload of `callAsFunction(_:_:)` handles the implicit conversions
482
- /// between various pointer types that are normally provided by the compiler.
483
- ///
484
- /// - Warning: This function is used to implement the `#expect()` and
485
- /// `#require()` macros. Do not call it directly.
486
- public mutating func callAsFunction< P> ( _ value: P , _ id: __ExpressionID ) -> UnsafeRawPointer where P: _Pointer {
487
- self ( value as P ? , id) !
452
+ @_disfavoredOverload
453
+ public mutating func callAsFunction< PFrom, PTo> ( _ value: PFrom , _ id: __ExpressionID ) -> PTo where PFrom: _Pointer , PTo: _Pointer {
454
+ self ( value as PFrom ? , id) as! PTo
488
455
}
489
456
490
457
/// Convert some pointer to an immutable one and capture information about it
@@ -502,8 +469,11 @@ extension __ExpectationContext {
502
469
///
503
470
/// - Warning: This function is used to implement the `#expect()` and
504
471
/// `#require()` macros. Do not call it directly.
505
- public mutating func callAsFunction< P> ( _ value: P ? , _ id: __ExpressionID ) -> UnsafeRawPointer ? where P: _Pointer {
506
- UnsafeRawPointer ( bitPattern: Int ( bitPattern: self ( value, id) as P ? ) )
472
+ @_disfavoredOverload
473
+ public mutating func callAsFunction< PFrom, PTo> ( _ value: PFrom ? , _ id: __ExpressionID ) -> PTo ? where PFrom: _Pointer , PTo: _Pointer {
474
+ value. flatMap { value in
475
+ PTo ( bitPattern: Int ( bitPattern: self ( value, id) as PFrom ) )
476
+ }
507
477
}
508
478
}
509
479
0 commit comments