Incorrect warning: '#require(_:_:)' is redundant because '<expression>' never equals 'nil' #79202
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
type checker
Area → compiler: Semantic analysis
Description
In a Swift Testing test, use of
#require
can in some cases result in a build warning about how the expression in the macro can never equal nil, even though it clearly can.For example, in swift-build, some tests have checks like this:
This results in the warning:
But
fileGroup.children
is of type[GroupTreeReference]
, so the check is downcasting it toFileReference
, which seems entirely valid to do, and could end up being nil if the instance is not aFileReference
. It works correctly, so the warning seems incorrect.#require
is being used here because it will emit an issue automatically if the expression is false or nil, which is the desired behavior. This could be worked around by not using#require
and instead handling that case with explicit code, but that seems unnecessary and contrary to the intent of#require
.Reproduction
See Description.
Expected behavior
This warning should not be emitted in cases such as the one in the Description.
Environment
Swift 6
Additional information
No response
The text was updated successfully, but these errors were encountered: