selectFunction selects the correct variant of a function based on the input types.
(fn *Function, inputExpressions []*expression.Expression, identifier *expression.Expression)
| 7 | "git.urbach.dev/cli/q/src/types" |
| 8 | ) |
| 9 | |
| 10 | // selectFunction selects the correct variant of a function based on the input types. |
| 11 | func (f *Function) selectFunction(fn *Function, values []ssa.Value, identifier *expression.Expression) (*Function, error) { |
| 12 | if fn.Next == nil { |
| 13 | if len(values) != len(fn.Input) { |
| 14 | return nil, errors.NewAt(&ParameterCountMismatch{Function: fn.FullName, Count: len(values), ExpectedCount: len(fn.Input)}, f.File, identifier.Source().End()) |
| 15 | } |
| 16 | |
| 17 | return fn, nil |
| 18 | } |
| 19 | |
| 20 | match: |
| 21 | for fn != nil { |
| 22 | if len(values) != len(fn.Input) { |
| 23 | fn = fn.Next |
| 24 | continue match |
| 25 | } |
| 26 | |
| 27 | for i, value := range values { |
| 28 | if !types.Is(value.Type(), fn.Input[i].Typ) { |
| 29 | fn = fn.Next |
| 30 | continue match |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return fn, nil |
| 35 | } |
| 36 | |
| 37 | return nil, nil |
| 38 | } |
no test coverage detected