@@ -511,44 +511,41 @@ func (v *visitor) checkFunc(fn reflect.Type, method bool, node *ast.CallNode, na
511
511
return v .error (node , "func %v returns more then two values" , name )
512
512
}
513
513
514
- numIn := fn .NumIn ()
515
-
516
514
// If func is method on an env, first argument should be a receiver,
517
- // and actual arguments less than numIn by one.
515
+ // and actual arguments less than fnNumIn by one.
516
+ fnNumIn := fn .NumIn ()
518
517
if method {
519
- numIn --
518
+ fnNumIn --
519
+ }
520
+ // Skip first argument in case of the receiver.
521
+ fnInOffset := 0
522
+ if method {
523
+ fnInOffset = 1
520
524
}
521
525
522
526
if fn .IsVariadic () {
523
- if len (arguments ) < numIn - 1 {
527
+ if len (arguments ) < fnNumIn - 1 {
524
528
return v .error (node , "not enough arguments to call %v" , name )
525
529
}
526
530
} else {
527
- if len (arguments ) > numIn {
531
+ if len (arguments ) > fnNumIn {
528
532
return v .error (node , "too many arguments to call %v" , name )
529
533
}
530
- if len (arguments ) < numIn {
534
+ if len (arguments ) < fnNumIn {
531
535
return v .error (node , "not enough arguments to call %v" , name )
532
536
}
533
537
}
534
538
535
- offset := 0
536
-
537
- // Skip first argument in case of the receiver.
538
- if method {
539
- offset = 1
540
- }
541
-
542
539
for i , arg := range arguments {
543
540
t , _ := v .visit (arg )
544
541
545
542
var in reflect.Type
546
- if fn .IsVariadic () && i >= numIn - 1 {
543
+ if fn .IsVariadic () && i >= fnNumIn - 1 {
547
544
// For variadic arguments fn(xs ...int), go replaces type of xs (int) with ([]int).
548
545
// As we compare arguments one by one, we need underling type.
549
546
in = fn .In (fn .NumIn () - 1 ).Elem ()
550
547
} else {
551
- in = fn .In (i + offset )
548
+ in = fn .In (i + fnInOffset )
552
549
}
553
550
554
551
if isIntegerOrArithmeticOperation (arg ) {
@@ -583,11 +580,11 @@ func (v *visitor) checkFunc(fn reflect.Type, method bool, node *ast.CallNode, na
583
580
continue funcTypes
584
581
}
585
582
}
586
- if typed .NumIn () != fn . NumIn () {
583
+ if typed .NumIn () != fnNumIn {
587
584
continue
588
585
}
589
586
for j := 0 ; j < typed .NumIn (); j ++ {
590
- if typed .In (j ) != fn .In (j ) {
587
+ if typed .In (j ) != fn .In (j + fnInOffset ) {
591
588
continue funcTypes
592
589
}
593
590
}
0 commit comments