Skip to content

Commit

Permalink
fix: struct type detection, collision between field and type name
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 12, 2019
1 parent 273df8a commit 275391c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ func (n *node) isType(sc *scope) bool {
}
case selectorExpr:
pkg, name := n.child[0].ident, n.child[1].ident
if sym, _, ok := sc.lookup(pkg); ok {
if sym, _, ok := sc.lookup(pkg); ok && sym.kind == pkgSym {
path := sym.typ.path
if p, ok := n.interp.binPkg[path]; ok && isBinType(p[name]) {
return true // Imported binary type
Expand Down
9 changes: 8 additions & 1 deletion interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
t.method = m
sym.typ = t
}
if t.node == nil {
t.node = n
}
} else {
t.incomplete = true
sc.sym[n.ident] = &symbol{kind: typeSym, typ: t}
Expand Down Expand Up @@ -995,7 +998,11 @@ func isInterface(t *itype) bool {
return isInterfaceSrc(t) || t.TypeOf().Kind() == reflect.Interface
}

func isStruct(t *itype) bool { return t.TypeOf().Kind() == reflect.Struct }
func isStruct(t *itype) bool {
// Test first for a struct category, because a recursive interpreter struct may be
// represented by an interface{} at reflect level.
return t.cat == structT || t.TypeOf().Kind() == reflect.Struct
}

func isBool(t *itype) bool { return t.TypeOf().Kind() == reflect.Bool }

Expand Down

0 comments on commit 275391c

Please sign in to comment.