@@ -269,12 +269,12 @@ extension __ExpectationContext {
269269 /// - Warning: This function is used to implement the `#expect()` and
270270 /// `#require()` macros. Do not call it directly.
271271 public mutating func __cmp< T, U, R> (
272+ _ op: ( T , U ) throws -> R ,
273+ _ opID: __ExpressionID ,
272274 _ lhs: T ,
273275 _ lhsID: __ExpressionID ,
274276 _ rhs: U ,
275- _ rhsID: __ExpressionID ,
276- _ op: ( T , U ) throws -> R ,
277- _ opID: __ExpressionID
277+ _ rhsID: __ExpressionID
278278 ) rethrows -> R {
279279 try self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
280280 }
@@ -287,12 +287,12 @@ extension __ExpectationContext {
287287 /// - Warning: This function is used to implement the `#expect()` and
288288 /// `#require()` macros. Do not call it directly.
289289 public mutating func __cmp< C> (
290+ _ op: ( C , C ) -> Bool ,
291+ _ opID: __ExpressionID ,
290292 _ lhs: C ,
291293 _ lhsID: __ExpressionID ,
292294 _ rhs: C ,
293- _ rhsID: __ExpressionID ,
294- _ op: ( C , C ) -> Bool ,
295- _ opID: __ExpressionID
295+ _ rhsID: __ExpressionID
296296 ) -> Bool where C: BidirectionalCollection , C. Element: Equatable {
297297 let result = self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
298298
@@ -309,17 +309,17 @@ extension __ExpectationContext {
309309 ///
310310 /// This overload of `__cmp()` does _not_ perform a diffing operation on `lhs`
311311 /// 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 ))
313313 ///
314314 /// - Warning: This function is used to implement the `#expect()` and
315315 /// `#require()` macros. Do not call it directly.
316316 public mutating func __cmp< R> (
317+ _ op: ( R , R ) -> Bool ,
318+ _ opID: __ExpressionID ,
317319 _ lhs: R ,
318320 _ lhsID: __ExpressionID ,
319321 _ rhs: R ,
320- _ rhsID: __ExpressionID ,
321- _ op: ( R , R ) -> Bool ,
322- _ opID: __ExpressionID
322+ _ rhsID: __ExpressionID
323323 ) -> Bool where R: RangeExpression & BidirectionalCollection , R. Element: Equatable {
324324 self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
325325 }
@@ -333,12 +333,12 @@ extension __ExpectationContext {
333333 /// - Warning: This function is used to implement the `#expect()` and
334334 /// `#require()` macros. Do not call it directly.
335335 public mutating func __cmp< S> (
336+ _ op: ( S , S ) -> Bool ,
337+ _ opID: __ExpressionID ,
336338 _ lhs: S ,
337339 _ lhsID: __ExpressionID ,
338340 _ rhs: S ,
339- _ rhsID: __ExpressionID ,
340- _ op: ( S , S ) -> Bool ,
341- _ opID: __ExpressionID
341+ _ rhsID: __ExpressionID
342342 ) -> Bool where S: StringProtocol {
343343 let result = self ( op ( self ( lhs, lhsID) , self ( rhs, rhsID) ) , opID)
344344
@@ -376,9 +376,11 @@ extension __ExpectationContext {
376376 ///
377377 /// - Parameters:
378378 /// - 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.
379381 /// - 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 .
382384 ///
383385 /// - Returns: The result of the expression `value as? type`.
384386 ///
@@ -388,12 +390,12 @@ extension __ExpectationContext {
388390 ///
389391 /// - Warning: This function is used to implement the `#expect()` and
390392 /// `#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
393395
394396 if result == nil {
395397 let correctType = Swift . type ( of: value as Any )
396- runtimeValues [ typeID ] = { Expression . Value ( reflecting : correctType) }
398+ _ = self ( correctType, typeID )
397399 }
398400
399401 return result
@@ -403,9 +405,11 @@ extension __ExpectationContext {
403405 ///
404406 /// - Parameters:
405407 /// - 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.
406410 /// - 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 .
409413 ///
410414 /// - Returns: The result of the expression `value as? type`.
411415 ///
@@ -415,12 +419,12 @@ extension __ExpectationContext {
415419 ///
416420 /// - Warning: This function is used to implement the `#expect()` and
417421 /// `#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
420424
421425 if !result {
422426 let correctType = Swift . type ( of: value as Any )
423- runtimeValues [ typeID ] = { Expression . Value ( reflecting : correctType) }
427+ _ = self ( correctType, typeID )
424428 }
425429
426430 return result
@@ -445,46 +449,9 @@ extension __ExpectationContext {
445449 ///
446450 /// - Warning: This function is used to implement the `#expect()` and
447451 /// `#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
488455 }
489456
490457 /// Convert some pointer to an immutable one and capture information about it
@@ -502,8 +469,11 @@ extension __ExpectationContext {
502469 ///
503470 /// - Warning: This function is used to implement the `#expect()` and
504471 /// `#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+ }
507477 }
508478}
509479
0 commit comments