Skip to content

failed-assertion-shadow-read

Default severity: warning

An if initializer such as if value, ok := value.(T); ok declares a new value that remains in scope in the else branch. When the assertion fails, that variable contains T’s zero value. Reading it in the failure branch often means the original interface value was intended.

if value, ok := value.(T); ok { use(value) } else { logType(value) }
if typed, ok := value.(T); ok { use(typed) } else { logType(value) }