kisielk / errcheck

errcheck checks that you checked errors.
MIT License
2.33k stars 138 forks source link

Report unchecked type-assertion when returning value and when passing it to other func #224

Closed leonklingele closed 3 months ago

leonklingele commented 1 year ago

Two false negatives here when using the -asserts flag:

package main

func main() {
    var i interface{} = "hello"

    _ = handleInterface(i)

    handleString(i.(string)) // This should be reported but isn't
}

func handleInterface(i interface{}) string {
    return i.(string) // This should be reported but isn't
}

func handleString(s string) {}
leonklingele commented 1 year ago

Also, this is not caught:

if i.(string) == "hello" {
    ..
}