Skip to content

Ensure the Bool overload of __checkBinaryOperation() is still preferred. #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public func __checkValue<T>(
///
/// - Warning: This function is used to implement the `#expect()` and
/// `#require()` macros. Do not call it directly.
public func __checkBinaryOperation<T>(
@_disfavoredOverload public func __checkBinaryOperation<T>(
_ lhs: T?, _ op: (T?, () -> T?) -> T?, _ rhs: @autoclosure () -> T?,
expression: __Expression,
comments: @autoclosure () -> [Comment],
Expand Down
17 changes: 17 additions & 0 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,23 @@ struct IssueCodingTests {
#expect(String(describing: issueSnapshot) == String(describing: issue))
#expect(String(reflecting: issueSnapshot) == String(reflecting: issue))
}

@Test func binaryOperatorExpansionPrefersBooleanOverOptional() async throws {
await confirmation("Issue recorded", expectedCount: 3) { issueRecorded in
var configuration = Configuration()
configuration.eventHandler = { event, _ in
if case .issueRecorded = event.kind {
issueRecorded()
}
}

await Test {
#expect(true == false)
#expect(false != false)
try #require(true != true)
}.run(configuration: configuration)
}
}
}
#endif

Expand Down