From ca9c302d807f47a55552d0a20a2dfcdb0fcc6e28 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 24 Jan 2018 11:35:22 +0100 Subject: pkg/compiler, prog: fix template parent lens It's possible that a struct can have 2+ parents, which is the same template (differs only by arguments). See the new test case. Support such case. --- pkg/compiler/check.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'pkg/compiler') diff --git a/pkg/compiler/check.go b/pkg/compiler/check.go index 1954fded5..bcb788a0c 100644 --- a/pkg/compiler/check.go +++ b/pkg/compiler/check.go @@ -269,15 +269,14 @@ func (comp *compiler) checkLenType(t *ast.Type, name string, fields []*ast.Field for i, arg := range args { argDesc := desc.Args[i] if argDesc.Type == typeArgLenTarget { - comp.checkLenTarget(t, name, &arg.Ident, fields, parents) + comp.checkLenTarget(t, name, arg.Ident, fields, parents) } else if argDesc.Type == typeArgType { comp.checkLenType(arg, name, fields, parents, checked, false) } } } -func (comp *compiler) checkLenTarget(t *ast.Type, name string, targetp *string, fields []*ast.Field, parents []*ast.Struct) { - target := *targetp +func (comp *compiler) checkLenTarget(t *ast.Type, name, target string, fields []*ast.Field, parents []*ast.Struct) { if target == name { comp.error(t.Pos, "%v target %v refer to itself", t.Ident, target) return @@ -315,12 +314,10 @@ func (comp *compiler) checkLenTarget(t *ast.Type, name string, targetp *string, for _, parent := range parents { parentName := parent.Name.Name if pos := strings.IndexByte(parentName, '['); pos != -1 { - // For template parents name is "struct_name[ARG1, ARG2]", - // strip the part after '[' and update actual len target. + // For template parents name is "struct_name[ARG1, ARG2]", strip the part after '['. parentName = parentName[:pos] } if target == parentName { - *targetp = parent.Name.Name return } } -- cgit mrf-deployment