Add adds the given function to the overload collection. Returns an error if the there's a problem with the function's declaration.
(function FunctionInterface)
| 42 | // Add adds the given function to the overload collection. Returns an error if the there's a problem with the |
| 43 | // function's declaration. |
| 44 | func (o *Overloads) Add(function FunctionInterface) error { |
| 45 | key := keyForParamTypes(function.GetParameters()) |
| 46 | if _, ok := o.ByParamType[key]; ok { |
| 47 | return errors.Errorf("duplicate function overload for `%s`", function.GetName()) |
| 48 | } |
| 49 | |
| 50 | if function.VariadicIndex() >= 0 { |
| 51 | varArgsType := function.GetParameters()[function.VariadicIndex()] |
| 52 | if !varArgsType.IsArrayType() { |
| 53 | return errors.Errorf("variadic parameter must be an array type for function `%s`", function.GetName()) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | o.ByParamType[key] = function |
| 58 | o.AllOverloads = append(o.AllOverloads, function) |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | // keyForParamTypes returns a string key to match an overload with the given parameter types. |
| 63 | func keyForParamTypes(types []*pgtypes.DoltgresType) string { |
no test coverage detected