MCPcopy
hub / github.com/expr-lang/expr / checkArguments

Method checkArguments

checker/checker.go:1050–1173  ·  view source on GitHub ↗
(
	name string,
	fn Nature,
	arguments []ast.Node,
	node ast.Node,
)

Source from the content-addressed store, hash-verified

1048}
1049
1050func (v *Checker) checkArguments(
1051 name string,
1052 fn Nature,
1053 arguments []ast.Node,
1054 node ast.Node,
1055) (Nature, *file.Error) {
1056 if fn.IsUnknown(&v.config.NtCache) {
1057 return Nature{}, nil
1058 }
1059
1060 numOut := fn.NumOut()
1061 if numOut == 0 {
1062 return Nature{}, &file.Error{
1063 Location: node.Location(),
1064 Message: fmt.Sprintf("func %v doesn't return value", name),
1065 }
1066 }
1067 if numOut > 2 {
1068 return Nature{}, &file.Error{
1069 Location: node.Location(),
1070 Message: fmt.Sprintf("func %v returns more then two values", name),
1071 }
1072 }
1073
1074 // If func is method on an env, first argument should be a receiver,
1075 // and actual arguments less than fnNumIn by one.
1076 fnNumIn := fn.NumIn()
1077 if fn.Method { // TODO: Move subtraction to the Nature.NumIn() and Nature.In() methods.
1078 fnNumIn--
1079 }
1080 // Skip first argument in case of the receiver.
1081 fnInOffset := 0
1082 if fn.Method {
1083 fnInOffset = 1
1084 }
1085
1086 var err *file.Error
1087 isVariadic := fn.IsVariadic()
1088 if isVariadic {
1089 if len(arguments) < fnNumIn-1 {
1090 err = &file.Error{
1091 Location: node.Location(),
1092 Message: fmt.Sprintf("not enough arguments to call %v", name),
1093 }
1094 }
1095 } else {
1096 if len(arguments) > fnNumIn {
1097 err = &file.Error{
1098 Location: node.Location(),
1099 Message: fmt.Sprintf("too many arguments to call %v", name),
1100 }
1101 }
1102 if len(arguments) < fnNumIn {
1103 err = &file.Error{
1104 Location: node.Location(),
1105 Message: fmt.Sprintf("not enough arguments to call %v", name),
1106 }
1107 }

Callers 2

callNodeMethod · 0.95
checkFunctionMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 15

visitMethod · 0.95
StringMethod · 0.95
IsUnknownMethod · 0.80
NumOutMethod · 0.80
SprintfMethod · 0.80
NumInMethod · 0.80
IsVariadicMethod · 0.80
OutMethod · 0.80
InElemMethod · 0.80
InMethod · 0.80

Tested by

no test coverage detected