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. --- prog/size.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'prog/size.go') diff --git a/prog/size.go b/prog/size.go index 36928a8bc..e2451fe15 100644 --- a/prog/size.go +++ b/prog/size.go @@ -5,6 +5,7 @@ package prog import ( "fmt" + "strings" ) func (target *Target) generateSize(arg Arg, lenType *LenType) uint64 { @@ -67,7 +68,12 @@ func (target *Target) assignSizes(args []Arg, parentsMap map[Arg]Arg) { sizeAssigned := false for parent := parentsMap[arg]; parent != nil; parent = parentsMap[parent] { - if typ.Buf == parent.Type().Name() { + parentName := parent.Type().Name() + if pos := strings.IndexByte(parentName, '['); pos != -1 { + // For template parents, strip arguments. + parentName = parentName[:pos] + } + if typ.Buf == parentName { a.Val = parent.Size() if typ.BitSize != 0 { a.Val = a.Val * 8 / typ.BitSize -- cgit mrf-deployment