aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-01-24 11:35:22 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-01-24 11:35:22 +0100
commitca9c302d807f47a55552d0a20a2dfcdb0fcc6e28 (patch)
tree2eb665c4c58d338671dedf8c70d617eebab2e202 /pkg
parente5b101ddff108ef913e8f7c6085eac52498443a0 (diff)
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.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/compiler/check.go9
1 files changed, 3 insertions, 6 deletions
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
}
}