@@ -643,11 +643,7 @@ retry:
643
643
src , pos := pkg .cb .loadExpr (fn .Src )
644
644
pkg .cb .panicCodeErrorf (& pos , "cannot call non-function %s (type %v)" , src , fn .Type )
645
645
}
646
- at := func () string {
647
- src , _ := pkg .cb .loadExpr (fn .Src )
648
- return "argument to " + src
649
- }
650
- if err = matchFuncType (pkg , args , flags , sig , at ); err != nil {
646
+ if err = matchFuncType (pkg , args , flags , sig , fn ); err != nil {
651
647
return
652
648
}
653
649
tyRet := toRetType (sig .Results (), it )
@@ -751,7 +747,7 @@ func toRetType(t *types.Tuple, it *instantiated) types.Type {
751
747
}
752
748
753
749
func matchFuncType (
754
- pkg * Package , args []* internal.Elem , flags InstrFlags , sig * types.Signature , at interface {} ) error {
750
+ pkg * Package , args []* internal.Elem , flags InstrFlags , sig * types.Signature , fn * internal. Elem ) error {
755
751
var t * types.Tuple
756
752
n := len (args )
757
753
if len (args ) == 1 && checkTuple (& t , args [0 ].Type ) {
@@ -768,6 +764,15 @@ func matchFuncType(
768
764
}
769
765
}
770
766
}
767
+ var at interface {}
768
+ if fn == nil {
769
+ at = "closure argument" // fn = nil means it is a closure
770
+ } else {
771
+ at = func () string {
772
+ src , _ := pkg .cb .loadExpr (fn .Src )
773
+ return "argument to " + src
774
+ }
775
+ }
771
776
if sig .Variadic () {
772
777
if (flags & InstrFlagEllipsis ) == 0 {
773
778
n1 := getParamLen (sig ) - 1
@@ -784,10 +789,25 @@ func matchFuncType(
784
789
return matchElemType (pkg , args [n1 :], tyVariadic .Elem (), at )
785
790
}
786
791
} else if (flags & InstrFlagEllipsis ) != 0 {
787
- return errors .New ("TODO: call with ... to non variadic function" )
792
+ var caller string
793
+ var pos token.Position
794
+ if fn != nil {
795
+ caller , pos = pkg .cb .loadExpr (fn .Src )
796
+ }
797
+ return pkg .cb .newCodeError (& pos , fmt .Sprintf ("invalid use of ... in call to %v" , caller ))
788
798
}
789
799
if nreq := getParamLen (sig ); nreq != n {
790
- return fmt .Errorf ("TODO: unmatched function parameters count, requires %v but got %v" , nreq , n )
800
+ fewOrMany := "few"
801
+ if n > nreq {
802
+ fewOrMany = "many"
803
+ }
804
+ var caller string
805
+ var pos token.Position
806
+ if fn != nil {
807
+ caller , pos = pkg .cb .loadExpr (fn .Src )
808
+ }
809
+ return pkg .cb .newCodeError (& pos , fmt .Sprintf (
810
+ "too %s arguments in call to %s\n \t have (%v)\n \t want %v" , fewOrMany , caller , getTypes (args ), sig .Params ()))
791
811
}
792
812
return matchFuncArgs (pkg , args , sig , at )
793
813
}
0 commit comments