Skip to content

Commit 7809190

Browse files
committed
Fix offset
1 parent d784db2 commit 7809190

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

checker/checker.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,24 @@ func (v *visitor) checkFunc(fn reflect.Type, method bool, node ast.Node, name st
364364
}
365365
}
366366

367-
n := 0
367+
offset := 0
368368

369369
// Skip first argument in case of the receiver.
370370
if method {
371-
n = 1
371+
offset = 1
372372
}
373373

374-
for _, arg := range arguments {
374+
for i, arg := range arguments {
375375
t := v.visit(arg)
376376

377377
var in reflect.Type
378-
if fn.IsVariadic() && n >= numIn {
378+
if fn.IsVariadic() && i >= numIn-1 {
379379
// For variadic arguments fn(xs ...int), go replaces type of xs (int) with ([]int).
380380
// As we compare arguments one by one, we need underling type.
381-
in, _ = indexType(fn.In(numIn))
381+
in = fn.In(fn.NumIn() - 1)
382+
in, _ = indexType(in)
382383
} else {
383-
in = fn.In(n)
384+
in = fn.In(i + offset)
384385
}
385386

386387
if isIntegerOrArithmeticOperation(arg) {
@@ -391,8 +392,6 @@ func (v *visitor) checkFunc(fn reflect.Type, method bool, node ast.Node, name st
391392
if !t.AssignableTo(in) {
392393
panic(v.error(arg, "cannot use %v as argument (type %v) to call %v ", t, in, name))
393394
}
394-
395-
n++
396395
}
397396

398397
return fn.Out(0)

0 commit comments

Comments
 (0)