fix: correct struct field name definition from imported type (#156)
This commit is contained in:
committed by
Ludovic Fernandez
parent
378252166b
commit
9b1a0c006c
22
_test/struct11.go
Normal file
22
_test/struct11.go
Normal 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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user