diff --git a/_test/switch21.go b/_test/switch21.go new file mode 100644 index 000000000..b13867d45 --- /dev/null +++ b/_test/switch21.go @@ -0,0 +1,17 @@ +package main + +import "fmt" + +func main() { + var err error + + switch v := err.(type) { + case fmt.Formatter: + println("formatter") + default: + fmt.Println(v) + } +} + +// Output: +// diff --git a/interp/cfg.go b/interp/cfg.go index ddb16cde2..be58db4b5 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -173,6 +173,10 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) { switch sym, _, ok := sc.lookup(n.child[0].ident); { case ok && sym.kind == typeSym: typ = sym.typ + case n.child[0].kind == selectorExpr: + if typ, err = nodeType(interp, sc, n.child[0]); err != nil { + return false + } case n.child[0].ident == "nil": typ = sc.getType("interface{}") default: