BinaryBinding provides the implementation of a binary overload. The provided function is protected by a runtime type-guard which ensures runtime type agreement between the overload signature and runtime argument types.
(binding functions.BinaryOp)
| 867 | // BinaryBinding provides the implementation of a binary overload. The provided function is protected by a runtime |
| 868 | // type-guard which ensures runtime type agreement between the overload signature and runtime argument types. |
| 869 | func BinaryBinding(binding functions.BinaryOp) OverloadOpt { |
| 870 | return func(o *OverloadDecl) (*OverloadDecl, error) { |
| 871 | if o.HasBinding() { |
| 872 | return nil, fmt.Errorf("overload already has a binding: %s", o.ID()) |
| 873 | } |
| 874 | if len(o.ArgTypes()) != 2 { |
| 875 | return nil, fmt.Errorf("binary function bound to non-binary overload: %s", o.ID()) |
| 876 | } |
| 877 | if o.hasLateBinding { |
| 878 | return nil, fmt.Errorf("overload already has a late binding: %s", o.ID()) |
| 879 | } |
| 880 | o.binaryOp = binding |
| 881 | return o, nil |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | // FunctionBinding provides the implementation of a variadic overload. The provided function is protected by a runtime |
| 886 | // type-guard which ensures runtime type agreement between the overload signature and runtime argument types. |