MCPcopy Create free account
hub / github.com/akyoto/q / selectFunction

Method selectFunction

src/core/selectFunction.go:9–40  ·  view source on GitHub ↗

selectFunction selects the correct variant of a function based on the input types.

(fn *Function, inputExpressions []*expression.Expression, identifier *expression.Expression)

Source from the content-addressed store, hash-verified

7 "git.urbach.dev/cli/q/src/types"
8)
9
10// selectFunction selects the correct variant of a function based on the input types.
11func (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
20match:
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}

Callers 1

evaluatePackageMemberMethod · 0.95

Calls 5

matchesTypeMethod · 0.95
NewAtFunction · 0.92
BlockMethod · 0.80
EndMethod · 0.65
SourceMethod · 0.45

Tested by

no test coverage detected