Skip to content

Commit

Permalink
fix: generate injection method with receiver (google#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
px3303 committed Aug 24, 2022
1 parent 0675cdc commit 574d7a8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/wire/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,16 @@ func injectPass(name string, sig *types.Signature, calls []call, set *ProviderSe
ig.p("%s\n", c.Text)
}
}
ig.p("func %s(", name)
var recv string
if v := sig.Recv(); v != nil {
switch t := v.Type().(type) {
case *types.Pointer:
recv = " (*" + t.Elem().(*types.Named).Obj().Name() + ")"
case *types.Named:
recv = " (" + t.Obj().Name() + ")"
}
}
ig.p("func%s %s(", recv, name)
for i := 0; i < params.Len(); i++ {
if i > 0 {
ig.p(", ")
Expand Down

0 comments on commit 574d7a8

Please sign in to comment.