Closed as duplicate of#79202
Description
Description
When using try #require
inside an optional assignment, an incorrect warning ist being produced:
'#require(_:_:)' is redundant because 'x' never equals 'nil' (from macro 'require')
Reproduction
import Testing
struct A {
var value: Int?
}
@Test func run() throws {
let one = A()
var two = A()
two.value = try #require(one.value)
// warning: '#require(_:_:)' is redundant because 'one.value' never equals 'nil' (from macro 'require')
}
Expected behavior
There should be no warning, the code is correct, as one.value
can indeed become nil
. Changing the code as follows does not have the warning:
@Test func run() throws {
let one = A()
let two = try #require(one.value)
}
Environment
Swift 6.1, Xcode Version 16.3 (16E140)
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Additional information
This was not an issue with Swift 6.0 and previous Xcode releases.