( name string, fn Nature, arguments []ast.Node, node ast.Node, )
| 1048 | } |
| 1049 | |
| 1050 | func (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 | } |
no test coverage detected