Skip to content

Commit b7d6de4

Browse files
committed
Tweaks to previous commit, disable expansion on some expressions the type checker is struggling with
1 parent 79d588a commit b7d6de4

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

Sources/Testing/Expectations/ExpectationContext.swift

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ extension __ExpectationContext {
430430
// MARK: - Implicit pointer conversion
431431

432432
extension __ExpectationContext {
433-
/// Convert a mutable pointer to an immutable one and capture information
434-
/// about it for use if the expectation currently being evaluated fails.
433+
/// Convert some pointer to an immutable one and capture information about it
434+
/// for use if the expectation currently being evaluated fails.
435435
///
436436
/// - Parameters:
437437
/// - value: The pointer to make immutable.
@@ -440,76 +440,70 @@ extension __ExpectationContext {
440440
///
441441
/// - Returns: `value`, cast to an immutable pointer.
442442
///
443-
/// This overload of `callAsFunction(_:_:)` handles the implicit conversion
444-
/// from a mutable to an immutable pointer that is normally provided by the
445-
/// compiler.
443+
/// This overload of `callAsFunction(_:_:)` handles the implicit conversions
444+
/// between various pointer types that are normally provided by the compiler.
446445
///
447446
/// - Warning: This function is used to implement the `#expect()` and
448447
/// `#require()` macros. Do not call it directly.
449-
public mutating func callAsFunction<T>(_ value: UnsafeMutablePointer<T>, _ id: __ExpressionID) -> UnsafePointer<T> {
450-
UnsafePointer(self(value, id) as UnsafeMutablePointer<T>)
448+
public mutating func callAsFunction<P, T>(_ value: P, _ id: __ExpressionID) -> UnsafePointer<T> where P: _Pointer {
449+
self(value as P?, id)!
451450
}
452451

453-
/// Convert an optional mutable pointer to an immutable one and capture
454-
/// information about it for use if the expectation currently being evaluated
455-
/// fails.
452+
/// Convert some pointer to an immutable one and capture information about it
453+
/// for use if the expectation currently being evaluated fails.
456454
///
457455
/// - Parameters:
458-
/// - value: The pointer to make immutable, or `nil`.
456+
/// - value: The pointer to make immutable.
459457
/// - id: A value that uniquely identifies the represented expression in the
460458
/// context of the expectation currently being evaluated.
461459
///
462460
/// - Returns: `value`, cast to an immutable pointer.
463461
///
464-
/// This overload of `callAsFunction(_:_:)` handles the implicit conversion
465-
/// from a mutable to an immutable pointer that is normally provided by the
466-
/// compiler.
462+
/// This overload of `callAsFunction(_:_:)` handles the implicit conversions
463+
/// between various pointer types that are normally provided by the compiler.
467464
///
468465
/// - Warning: This function is used to implement the `#expect()` and
469466
/// `#require()` macros. Do not call it directly.
470-
public mutating func callAsFunction<T>(_ value: UnsafeMutablePointer<T>?, _ id: __ExpressionID) -> UnsafePointer<T>? {
471-
UnsafePointer(self(value, id) as UnsafeMutablePointer<T>?)
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?))
472469
}
473470

474-
/// Convert a mutable raw pointer to an immutable one and capture information
475-
/// about it for use if the expectation currently being evaluated fails.
471+
/// Convert some pointer to an immutable one and capture information about it
472+
/// for use if the expectation currently being evaluated fails.
476473
///
477474
/// - Parameters:
478475
/// - value: The pointer to make immutable.
479476
/// - id: A value that uniquely identifies the represented expression in the
480477
/// context of the expectation currently being evaluated.
481478
///
482-
/// - Returns: `value`, cast to an immutable raw pointer.
479+
/// - Returns: `value`, cast to an immutable pointer.
483480
///
484-
/// This overload of `callAsFunction(_:_:)` handles the implicit conversion
485-
/// from a mutable to an immutable pointer that is normally provided by the
486-
/// compiler.
481+
/// This overload of `callAsFunction(_:_:)` handles the implicit conversions
482+
/// between various pointer types that are normally provided by the compiler.
487483
///
488484
/// - Warning: This function is used to implement the `#expect()` and
489485
/// `#require()` macros. Do not call it directly.
490-
public mutating func callAsFunction(_ value: UnsafeMutableRawPointer, _ id: __ExpressionID) -> UnsafeRawPointer {
491-
UnsafeRawPointer(self(value, id) as UnsafeMutableRawPointer)
486+
public mutating func callAsFunction<P>(_ value: P, _ id: __ExpressionID) -> UnsafeRawPointer where P: _Pointer {
487+
self(value as P?, id)!
492488
}
493489

494-
/// Convert an optional mutable raw pointer to an immutable one and capture
495-
/// information about it for use if the expectation currently being evaluated
496-
/// fails.
490+
/// Convert some pointer to an immutable one and capture information about it
491+
/// for use if the expectation currently being evaluated fails.
497492
///
498493
/// - Parameters:
499-
/// - value: The pointer to make immutable, or `nil`.
494+
/// - value: The pointer to make immutable.
500495
/// - id: A value that uniquely identifies the represented expression in the
501496
/// context of the expectation currently being evaluated.
502497
///
503-
/// - Returns: `value`, cast to an immutable raw pointer.
498+
/// - Returns: `value`, cast to an immutable pointer.
504499
///
505-
/// This overload of `callAsFunction(_:_:)` handles the implicit conversion
506-
/// from a mutable to an immutable pointer that is normally provided by the
507-
/// compiler.
500+
/// This overload of `callAsFunction(_:_:)` handles the implicit conversions
501+
/// between various pointer types that are normally provided by the compiler.
508502
///
509503
/// - Warning: This function is used to implement the `#expect()` and
510504
/// `#require()` macros. Do not call it directly.
511-
public mutating func callAsFunction(_ value: UnsafeMutableRawPointer?, _ id: __ExpressionID) -> UnsafeRawPointer? {
512-
UnsafeRawPointer(self(value, id) as UnsafeMutableRawPointer?)
505+
public mutating func callAsFunction<P>(_ value: P?, _ id: __ExpressionID) -> UnsafeRawPointer? where P: _Pointer {
506+
UnsafeRawPointer(bitPattern: Int(bitPattern: self(value, id) as P?))
513507
}
514508
}
515509

@@ -539,9 +533,9 @@ extension __ExpectationContext {
539533
///
540534
/// - Warning: This function is used to implement the `#expect()` and
541535
/// `#require()` macros. Do not call it directly.
542-
public mutating func callAsFunction<P>(_ value: String, _ id: __ExpressionID) -> P where P: _Pointer {
536+
public mutating func callAsFunction<P>(_ value: String, _ id: __ExpressionID) -> P where P: _Pointer, P.Pointee == CChar {
543537
// Perform the normal value capture.
544-
let result = self(value, id)
538+
let result = self(value, id) as String
545539

546540
// Create a C string copy of `value`.
547541
#if os(Windows)

Sources/TestingMacros/Support/ConditionArgumentParsing.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ private final class _ContextInserter<C, M>: SyntaxRewriter where C: MacroExpansi
300300
ExprSyntax(node)
301301
}
302302

303+
override func visit(_ node: MacroExpansionExprSyntax) -> ExprSyntax {
304+
// We do not attempt to descent into freestanding macros.
305+
ExprSyntax(node)
306+
}
307+
303308
override func visit(_ node: FunctionDeclSyntax) -> DeclSyntax {
304309
// We do not (currently) attempt to descent into functions.
305310
DeclSyntax(node)
@@ -503,6 +508,14 @@ private final class _ContextInserter<C, M>: SyntaxRewriter where C: MacroExpansi
503508
originalWas: node
504509
)
505510
}
511+
#else
512+
override func visit(_ node: ArrayExprSyntax) -> ExprSyntax {
513+
return ExprSyntax(node)
514+
}
515+
516+
override func visit(_ node: DictionaryExprSyntax) -> ExprSyntax {
517+
return ExprSyntax(node)
518+
}
506519
#endif
507520
}
508521

Tests/TestingTests/Support/CartesianProductTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ struct CartesianProductTests {
3030
func count() {
3131
// Test the size of the product is correct.
3232
let (c1, c2, product) = computeCartesianProduct()
33-
#expect(product.underestimatedCount == (c1.underestimatedCount * c2.underestimatedCount))
34-
#expect(Array(product).count == (c1.count * c2.count))
35-
#expect(Array(product).count == (26 * 100))
33+
#expect((product.underestimatedCount == c1.underestimatedCount * c2.underestimatedCount) as Bool)
34+
#expect((Array(product).count == c1.count * c2.count) as Bool)
35+
#expect((Array(product).count == 26 * 100) as Bool)
3636
}
3737

3838
@Test("First element is correct")

0 commit comments

Comments
 (0)