Check for field and method name collisions.

This commit is contained in:
Nigel Tao committed 2017-06-18 09:10:17 +10:00
1 parent 380fe3d76f
commit ae20422754
1 file changed
+13
+13
View File
@@ -149,6 +149,7 @@ var phases = [...]struct {
{a.KFunc, (*Checker).checkFuncSignature},
{a.KFunc, (*Checker).checkFuncContract},
{a.KFunc, (*Checker).checkFuncBody},
{a.KStruct, (*Checker).checkFieldMethodCollisions},
}
type Checker struct {
@@ -434,6 +435,18 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
return nil
}
func (c *Checker) checkFieldMethodCollisions(node *a.Node) error {
n := node.Struct()
for _, o := range n.Fields() {
qid := t.QID{n.Name(), o.Field().Name()}
if _, ok := c.funcs[qid]; ok {
return fmt.Errorf("check: struct %q has both a field and method named %q",
qid[0].String(c.tm), qid[1].String(c.tm))
}
}
return nil
}
type checker struct {
c *Checker
tm *t.Map