Skip to content

Commit

Permalink
fix: handle selector expression in type switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Nov 25, 2019
1 parent 786ea36 commit d44e4af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions _test/switch21.go
Original file line number Diff line number Diff line change
@@ -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:
// <nil>
4 changes: 4 additions & 0 deletions interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d44e4af

Please sign in to comment.