(node *ast.CallNode)
| 636 | } |
| 637 | |
| 638 | func (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 | |
| 695 | func (v *Checker) builtinNode(node *ast.BuiltinNode) Nature { |
no test coverage detected