mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
8a0f76861d
Allow developers to control the behavior of warnings like this:
```
let x = 0
if case _ = x { // warning: 'if' condition is always true
// ...
}
```
Resolves rdar://178154296.
1.3 KiB
1.3 KiB
Useless conditional statement (UselessConditionalStatement)
Warnings that identify conditional statements (if, while, and guard) whose conditions can never be false.
Overview
When the condition of an if, while, or guard statement is statically known to always be true, the conditional structure is unnecessary. For if and while, the body always executes (and a while loop with no break would never terminate); for guard, the else branch is unreachable.
Examples
let x = 0
if case _ = x { // warning: 'if' condition is always true
// ...
}
while case _ = x { // warning: 'while' condition is always true
break
}
guard case _ = x else { // warning: 'guard' condition is always true, body is unreachable
fatalError()
}
In the examples above, the pattern matching conditions (case _ = ...) can never fail.