mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 00:47:28 +01:00
Check for field and method name collisions.
This commit is contained in:
1 parent
380fe3d76f
commit
ae20422754
1 file changed
+13
@@ -149,6 +149,7 @@ var phases = [...]struct {
|
|||||||
{a.KFunc, (*Checker).checkFuncSignature},
|
{a.KFunc, (*Checker).checkFuncSignature},
|
||||||
{a.KFunc, (*Checker).checkFuncContract},
|
{a.KFunc, (*Checker).checkFuncContract},
|
||||||
{a.KFunc, (*Checker).checkFuncBody},
|
{a.KFunc, (*Checker).checkFuncBody},
|
||||||
|
{a.KStruct, (*Checker).checkFieldMethodCollisions},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Checker struct {
|
type Checker struct {
|
||||||
@@ -434,6 +435,18 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
|||||||
return nil
|
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 {
|
type checker struct {
|
||||||
c *Checker
|
c *Checker
|
||||||
tm *t.Map
|
tm *t.Map
|
||||||
|
|||||||
Reference in new issue
Block a user