Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] pkg/ottl check for condition first #14614

Merged
merged 1 commit into from
Oct 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions pkg/ottl/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ type EnumParser func(*EnumSymbol) (*Enum, error)
type Enum int64

func (p *Parser[K]) newFunctionCall(inv invocation) (ExprFunc[K], error) {
if f, ok := p.functions[inv.Function]; ok {
args, err := p.buildArgs(inv, reflect.TypeOf(f))
if err != nil {
return nil, err
}

returnVals := reflect.ValueOf(f).Call(args)
f, ok := p.functions[inv.Function]
if !ok {
return nil, fmt.Errorf("undefined function %v", inv.Function)
}
args, err := p.buildArgs(inv, reflect.TypeOf(f))
if err != nil {
return nil, err
}

if returnVals[1].IsNil() {
err = nil
} else {
err = returnVals[1].Interface().(error)
}
returnVals := reflect.ValueOf(f).Call(args)

return returnVals[0].Interface().(ExprFunc[K]), err
if returnVals[1].IsNil() {
err = nil
} else {
err = returnVals[1].Interface().(error)
}
return nil, fmt.Errorf("undefined function %v", inv.Function)

return returnVals[0].Interface().(ExprFunc[K]), err
}

func (p *Parser[K]) buildArgs(inv invocation, fType reflect.Type) ([]reflect.Value, error) {
Expand Down