Swift

Swift

Made by DeepSource

Comparing two identical operands is likely a mistake SW-W1015

Bug risk
Critical

Comparing two identical operands in a binary operator can be a mistake. If two identical operands are used in a binary operator, the result is always predictable and will always be true. This can lead to unintended consequences if the code is meant to compare two different variables.

Bad Practice

let x = 10
let y = 5
if x == x {
    print("x is equal to x")
}

Recommended

let x = 10
let y = 5
if x == y {
    print("x is equal to y")
}