Skip to content

Commit 73d4948

Browse files
authored
Ensure the Bool overload of __checkBinaryOperation() is still preferred. (#797)
We noticed that in some conditions, boolean arguments to `#expect()` would compile to use the _optional_ overload of `__checkBinaryOperation()`, which would result in a pass when a failure should have occurred because the boolean value never evaluated to `nil`. This PR should resolve that issue. Resolves rdar://138964155. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 143406a commit 73d4948

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: Sources/Testing/Expectations/ExpectationChecking+Macro.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public func __checkValue<T>(
770770
///
771771
/// - Warning: This function is used to implement the `#expect()` and
772772
/// `#require()` macros. Do not call it directly.
773-
public func __checkBinaryOperation<T>(
773+
@_disfavoredOverload public func __checkBinaryOperation<T>(
774774
_ lhs: T?, _ op: (T?, () -> T?) -> T?, _ rhs: @autoclosure () -> T?,
775775
expression: __Expression,
776776
comments: @autoclosure () -> [Comment],

Diff for: Tests/TestingTests/IssueTests.swift

+17
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,23 @@ struct IssueCodingTests {
15521552
#expect(String(describing: issueSnapshot) == String(describing: issue))
15531553
#expect(String(reflecting: issueSnapshot) == String(reflecting: issue))
15541554
}
1555+
1556+
@Test func binaryOperatorExpansionPrefersBooleanOverOptional() async throws {
1557+
await confirmation("Issue recorded", expectedCount: 3) { issueRecorded in
1558+
var configuration = Configuration()
1559+
configuration.eventHandler = { event, _ in
1560+
if case .issueRecorded = event.kind {
1561+
issueRecorded()
1562+
}
1563+
}
1564+
1565+
await Test {
1566+
#expect(true == false)
1567+
#expect(false != false)
1568+
try #require(true != true)
1569+
}.run(configuration: configuration)
1570+
}
1571+
}
15551572
}
15561573
#endif
15571574

0 commit comments

Comments
 (0)