@@ -131,43 +131,57 @@ func (s *Searcher) applyMethodImplementationsInPackages(method *InjectionMethod,
131131 for gateIndex := range method .Gates {
132132 gate := & method .Gates [gateIndex ]
133133 callMethod := callExpr .Fun
134- callParam := callExpr .Args [gate .Index ]
135-
136- paramType := astPackage .TypesInfo .TypeOf (callParam )
137- targetName , targetPos , valid := s .extractTargetFromCallParam (paramType )
138- if ! valid {
139- // unknown injection type, possible generics or other not known
140- // go features on current moment
141- // we can extend this function later for new cases
142- continue
143- }
144134
145- targetDefinitions := s .sourceFromToken (targetPos )
146- if targetDefinitions .Import == method .Definition .Import {
147- // injector use our public interface for typing
148- // we exclude this cases from more deep analyse, because of runtime
149- // types injection. (we have not known type on compile time)
135+ // variadic function arguments may be absent in callExpr.Args
136+ if gate .IsVariadic && len (callExpr .Args ) <= gate .Index {
150137 continue
151138 }
152-
153- if ! targetDefinitions .Place .Valid {
154- // invalid target
155- // possible is some not importable std const like `errors`
156- // or not known ast at this moment
157- continue
139+ maxIdx := gate .Index
140+ if gate .IsVariadic {
141+ // variadic function arguments are passed as individual elements in callExpr.Args
142+ // iterate over callExpr.Args to process all variadic arguments
143+ maxIdx = len (callExpr .Args ) - 1
158144 }
159145
160- gate .Implementations = append (gate .Implementations , Implementation {
161- Injector : Injector {
162- CodeName : s .extractCodeFromASTNode (callParam ),
163- ParamDefinition : s .sourceFromToken (callParam .Pos ()),
164- MethodDefinition : s .sourceFromToken (callMethod .Pos ()),
165- },
166- Target : Target {
167- StructName : targetName ,
168- Definition : targetDefinitions ,
169- },
170- })
146+ for idx := gate .Index ; idx <= maxIdx ; idx ++ {
147+ callParam := callExpr .Args [idx ]
148+
149+ paramType := astPackage .TypesInfo .TypeOf (callParam )
150+ targetName , targetPos , valid := s .extractTargetFromCallParam (paramType )
151+ if ! valid {
152+ // unknown injection type, possible generics or other not known
153+ // go features on current moment
154+ // we can extend this function later for new cases
155+ continue
156+ }
157+
158+ targetDefinitions := s .sourceFromToken (targetPos )
159+ if targetDefinitions .Import == method .Definition .Import {
160+ // injector use our public interface for typing
161+ // we exclude this cases from more deep analyse, because of runtime
162+ // types injection. (we have not known type on compile time)
163+ continue
164+ }
165+
166+ if ! targetDefinitions .Place .Valid {
167+ // invalid target
168+ // possible is some not importable std const like `errors`
169+ // or not known ast at this moment
170+ continue
171+ }
172+
173+ gate .Implementations = append (gate .Implementations , Implementation {
174+ Injector : Injector {
175+ CodeName : s .extractCodeFromASTNode (callParam ),
176+ ParamDefinition : s .sourceFromToken (callParam .Pos ()),
177+ MethodDefinition : s .sourceFromToken (callMethod .Pos ()),
178+ },
179+ Target : Target {
180+ StructName : targetName ,
181+ Definition : targetDefinitions ,
182+ },
183+ })
184+ }
171185 }
172186 })
173187 }
0 commit comments