Some conditions become unsafe when not exhaustive. It is recommended to introduce complete condition checking to avoid bug risks.
In the following example, the slice xs
may be of zero length, but
not necessarily nil
(say, when xs := make([]SomeType, 0)
). Hence, the second
part of the condition will panic if there are no elements yet.
xs != nil && xs[0] != nil
len(xs) != 0 && xs[0] != nil