MCPcopy Index your code
hub / github.com/expr-lang/expr / callNode

Method callNode

checker/checker.go:638–693  ·  view source on GitHub ↗
(node *ast.CallNode)

Source from the content-addressed store, hash-verified

636}
637
638func (v *Checker) callNode(node *ast.CallNode) Nature {
639 // Check if type was set on node (for example, by patcher)
640 // and use node type instead of function return type.
641 //
642 // If node type is anyType, then we should use function
643 // return type. For example, on error we return anyType
644 // for a call `errCall().Method()` and method will be
645 // evaluated on `anyType.Method()`, so return type will
646 // be anyType `anyType.Method(): anyType`. Patcher can
647 // fix `errCall()` to return proper type, so on second
648 // checker pass we should replace anyType on method node
649 // with new correct function return type.
650 if typ := node.Type(); typ != nil && typ != anyType {
651 return *node.Nature()
652 }
653
654 // $env is not callable.
655 if id, ok := node.Callee.(*ast.IdentifierNode); ok && id.Value == "$env" {
656 return v.error(node, "%s is not callable", v.config.Env.String())
657 }
658
659 nt := v.visit(node.Callee)
660 if nt.IsUnknown(&v.config.NtCache) {
661 return Nature{}
662 }
663
664 if nt.TypeData != nil && nt.TypeData.Func != nil {
665 return v.checkFunction(nt.TypeData.Func, node, node.Arguments)
666 }
667
668 fnName := "function"
669 if identifier, ok := node.Callee.(*ast.IdentifierNode); ok {
670 fnName = identifier.Value
671 }
672 if member, ok := node.Callee.(*ast.MemberNode); ok {
673 if name, ok := member.Property.(*ast.StringNode); ok {
674 fnName = name.Value
675 }
676 }
677
678 if nt.Nil {
679 return v.error(node, "%v is nil; cannot call nil as function", fnName)
680 }
681
682 if nt.Kind == reflect.Func {
683 outType, err := v.checkArguments(fnName, nt, node.Arguments, node)
684 if err != nil {
685 if v.err == nil {
686 v.err = err
687 }
688 return Nature{}
689 }
690 return outType
691 }
692 return v.error(node, "%s is not callable", nt.String())
693}
694
695func (v *Checker) builtinNode(node *ast.BuiltinNode) Nature {

Callers 1

visitMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 8

errorMethod · 0.95
visitMethod · 0.95
checkFunctionMethod · 0.95
checkArgumentsMethod · 0.95
IsUnknownMethod · 0.80
TypeMethod · 0.65
NatureMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected