Go

Go

Made by DeepSource

Unreachable case clause in a type switch SCC-SA4020

Bug risk
Major

Beware of unreachable case clause in a type switch.

In a type switch like the following,

type T struct{}
func (T) Read(b []byte) (int, error) { return 0, nil }

var v interface{} = T{}

switch v.(type) {
case io.Reader:
    // ...
case T:
    // unreachable
}

The second case clause can never be reached because T implements io.Reader and case clauses are evaluated in source order.