AsFunctionOption converts the serializable form of the Overload into a function declaration option.
(tp types.Provider)
| 439 | |
| 440 | // AsFunctionOption converts the serializable form of the Overload into a function declaration option. |
| 441 | func (od *Overload) AsFunctionOption(tp types.Provider) (decls.FunctionOpt, error) { |
| 442 | if err := od.Validate(); err != nil { |
| 443 | return nil, err |
| 444 | } |
| 445 | args := make([]*types.Type, len(od.Args)) |
| 446 | var err error |
| 447 | var errs []error |
| 448 | for i, a := range od.Args { |
| 449 | args[i], err = a.AsCELType(tp) |
| 450 | if err != nil { |
| 451 | errs = append(errs, err) |
| 452 | } |
| 453 | } |
| 454 | result, err := od.Return.AsCELType(tp) |
| 455 | if err != nil { |
| 456 | errs = append(errs, err) |
| 457 | } |
| 458 | if od.Target != nil { |
| 459 | t, err := od.Target.AsCELType(tp) |
| 460 | if err != nil { |
| 461 | return nil, errors.Join(append(errs, err)...) |
| 462 | } |
| 463 | args = append([]*types.Type{t}, args...) |
| 464 | return decls.MemberOverload(od.ID, args, result), nil |
| 465 | } |
| 466 | if len(errs) != 0 { |
| 467 | return nil, errors.Join(errs...) |
| 468 | } |
| 469 | return decls.Overload(od.ID, args, result, decls.OverloadExamples(od.Examples...)), nil |
| 470 | } |
| 471 | |
| 472 | // NewExtension creates a serializable Extension from a name and version string. |
| 473 | func NewExtension(name string, version uint32) *Extension { |
no test coverage detected