Skip to content
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 @@ -557,7 +557,7 @@ public func __checkPropertyAccess<T, U>(
return __checkValue(
optionalValue,
expression: expression,
expressionWithCapturedRuntimeValues: expression.capturingRuntimeValues(lhs, optionalValue),
expressionWithCapturedRuntimeValues: expression.capturingRuntimeValues(lhs, optionalValue as U??),
comments: comments(),
isRequired: isRequired,
sourceLocation: sourceLocation
Expand Down Expand Up @@ -731,7 +731,7 @@ public func __checkBinaryOperation<T>(
return __checkValue(
optionalValue,
expression: expression,
expressionWithCapturedRuntimeValues: expression.capturingRuntimeValues(lhs, rhs),
expressionWithCapturedRuntimeValues: expression.capturingRuntimeValues(lhs as T??, rhs as T??),
comments: comments(),
isRequired: isRequired,
sourceLocation: sourceLocation
Expand Down
22 changes: 22 additions & 0 deletions Tests/TestingTests/IssueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,28 @@ final class IssueTests: XCTestCase {
await fulfillment(of: [rhsCalled], timeout: 0.0)
}

func testRequireOptionalMemberAccessEvaluatesToNil() async {
var configuration = Configuration()
configuration.eventHandler = { event, _ in
guard case let .issueRecorded(issue) = event.kind else {
return
}
XCTAssertFalse(issue.isKnown)
guard case let .expectationFailed(expectation) = issue.kind else {
XCTFail("Unexpected issue kind \(issue.kind)")
return
}
let expression = expectation.evaluatedExpression
XCTAssertTrue(expression.expandedDescription().contains("nil"))
XCTAssertFalse(expression.expandedDescription().contains("<not evaluated>"))
}

await Test {
let array = [String]()
_ = try #require(array.first)
}.run(configuration: configuration)
}

func testOptionalOperand() async {
let expectationFailed = expectation(description: "Expectation failed")

Expand Down