Exec implements the InterpretableV2 interface method.
(frame *ExecutionFrame)
| 635 | |
| 636 | // Exec implements the InterpretableV2 interface method. |
| 637 | func (un *evalUnary) Exec(frame *ExecutionFrame) ref.Val { |
| 638 | argVal := un.arg.Exec(frame) |
| 639 | // Early return if the argument to the function is error or unknown in strict mode. |
| 640 | strict := !un.nonStrict |
| 641 | if strict { |
| 642 | switch v := argVal.(type) { |
| 643 | case *types.Err: |
| 644 | // To preserve legacy cost tracking behavior for logical not, |
| 645 | // this cost is tracked, but will be removed in the future. |
| 646 | if un.function == operators.LogicalNot { |
| 647 | if costs := frame.CostTracker(); costs != nil { |
| 648 | costs.EvalUnary(frame, un.id, un, argVal, argVal) |
| 649 | } |
| 650 | } |
| 651 | return v |
| 652 | case *types.Unknown: |
| 653 | if costs := frame.CostTracker(); costs != nil { |
| 654 | costs.EvalUnary(frame, un.id, un, argVal, argVal) |
| 655 | } |
| 656 | return v |
| 657 | } |
| 658 | } |
| 659 | var res ref.Val |
| 660 | // If the implementation is bound and the argument value has the right traits required to |
| 661 | // invoke it, then call the implementation. |
| 662 | if un.impl != nil && (un.trait == 0 || matchOperandTrait(un.trait, strict, argVal)) { |
| 663 | res = labelErrNode(un.id, un.impl(argVal)) |
| 664 | } else if argVal.Type().HasTrait(traits.ReceiverType) { |
| 665 | // Otherwise, if the argument is a ReceiverType attempt to invoke the receiver method on the |
| 666 | // operand (arg0). |
| 667 | res = labelErrNode(un.id, argVal.(traits.Receiver).Receive(un.function, un.overload, []ref.Val{})) |
| 668 | } else { |
| 669 | res = types.NewErrWithNodeID(un.id, "no such overload: %s", un.function) |
| 670 | } |
| 671 | if costs := frame.CostTracker(); costs != nil { |
| 672 | costs.EvalUnary(frame, un.id, un, argVal, res) |
| 673 | } |
| 674 | return res |
| 675 | } |
| 676 | |
| 677 | // Eval implements the Interpretable interface method. |
| 678 | func (un *evalUnary) Eval(ctx Activation) ref.Val { |
nothing calls this directly
no test coverage detected