From 8b7379c11fa1d6abdf85698ca3c44793c607c158 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 20 Jul 2021 14:49:41 +0800 Subject: [PATCH] NewFuncWith bugfix --- func.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/func.go b/func.go index 594b7c03..c13e3264 100644 --- a/func.go +++ b/func.go @@ -110,7 +110,6 @@ func (p *Package) NewFuncWith(name string, sig *types.Signature) *Func { } fn := types.NewFunc(token.NoPos, p.Types, name, sig) - p.Types.Scope().Insert(fn) if recv := sig.Recv(); recv != nil { // add method to this type var t *types.Named switch typ := recv.Type().(type) { @@ -122,6 +121,8 @@ func (p *Package) NewFuncWith(name string, sig *types.Signature) *Func { panic("TODO: invalid recv type") } t.AddMethod(fn) + } else { + p.Types.Scope().Insert(fn) } decl := &ast.FuncDecl{}