From b92d5078343f85be5ac21faaa49780f25fed41bf Mon Sep 17 00:00:00 2001 From: kozmod Date: Sun, 25 Jun 2023 17:16:19 +0300 Subject: [PATCH] #648: fix invalid code generation when interface method parameter's name is the same as interface name --- pkg/generator.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/generator.go b/pkg/generator.go index 96f7e5bd..c356abd9 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -193,11 +193,10 @@ func (g *Generator) mockName() string { } // getTypeConstraintString returns type constraint string for a given interface. -// For instance, a method using this constraint: // -// func Foo[T Stringer](s []T) (ret []string) { -// -// } +// For instance, a method using this constraint: +// func Foo[T Stringer](s []T) (ret []string) { +// } // // The constraint returned will be "[T Stringer]" // @@ -495,7 +494,10 @@ func (g *Generator) genList(ctx context.Context, list *types.Tuple, variadic boo } } - pname := v.Name() + pname := v.Name()x + if ts == pname { + pname = fmt.Sprintf("%s%d", pname, i) + } if g.nameCollides(pname) || pname == "" { pname = fmt.Sprintf("_a%d", i)