Skip to content

Commit

Permalink
NewFuncWith
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jul 4, 2021
1 parent d4e0604 commit eed7ec2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion func.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ func (p *Func) End(cb *CodeBuilder) {

// NewFunc func
func (p *Package) NewFunc(recv *Param, name string, params, results *Tuple, variadic bool) *Func {
sig := types.NewSignature(recv, params, results, variadic)
return p.NewFuncWith(name, sig)
}

// NewFuncWith func
func (p *Package) NewFuncWith(name string, sig *types.Signature) *Func {
if name == "" {
panic("TODO: no func name")
}
p.endImport()

sig := types.NewSignature(recv, params, results, variadic)
fn := types.NewFunc(token.NoPos, p.Types, name, sig)
p.Types.Scope().Insert(fn)

Expand Down
2 changes: 1 addition & 1 deletion package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func domTest(t *testing.T, pkg *gox.Package, expected string) {
var b bytes.Buffer
err := gox.WriteTo(&b, pkg)
if err != nil {
t.Fatal("conv.WriteTo failed:", err)
t.Fatal("gox.WriteTo failed:", err)
}
result := b.String()
if result != expected {
Expand Down

0 comments on commit eed7ec2

Please sign in to comment.