fix: correct struct field name definition from imported type (#156)

This commit is contained in:
Marc Vertes
2019-04-16 17:38:28 +02:00
committed by Ludovic Fernandez
parent 378252166b
commit 9b1a0c006c
2 changed files with 30 additions and 1 deletions

22
_test/struct11.go Normal file
View File

@@ -0,0 +1,22 @@
package main
import (
"fmt"
"net/http"
)
type Fromage struct {
http.ResponseWriter
}
func main() {
a := Fromage{}
if a.ResponseWriter == nil {
fmt.Println("nil")
} else {
fmt.Println("not nil")
}
}
// Output:
// nil

View File

@@ -341,7 +341,14 @@ func nodeType(interp *Interpreter, scope *Scope, n *Node) (*Type, error) {
if err != nil {
return nil, err
}
t.field = append(t.field, StructField{name: c.child[0].ident, embed: true, typ: typ})
name := c.child[0].ident
if name == "" && c.child[0].kind == SelectorExpr {
name = c.child[0].child[1].ident
}
if name == "" {
return nil, n.cfgError("empty field name")
}
t.field = append(t.field, StructField{name: name, embed: true, typ: typ})
t.incomplete = t.incomplete || typ.incomplete
} else {
l := len(c.child)