combine assembles a new compositionStep from the target output step an an input output step. non-optional.combine(non-optional) // non-optional (non-optional && conditional).combine(optional) // optional (non-optional && unconditional).combine(optional) // non-optional The last combination case is
(step compositionStep)
| 473 | // The last combination case is unusual, but effectively it means that the non-optional value prunes away |
| 474 | // the potential optional output. |
| 475 | func (s nonOptionalCompositionStep) combine(step compositionStep) compositionStep { |
| 476 | if step == nil { |
| 477 | // The input `step` may be nil if this is the first compositionStep |
| 478 | return s |
| 479 | } |
| 480 | ctx := s.ctx |
| 481 | trueCondition := ctx.NewLiteral(types.True) |
| 482 | if step.isOptional() { |
| 483 | // If the step is optional, convert the non-optional value to an optional one and return a ternary |
| 484 | if s.isConditional() { |
| 485 | return newOptionalCompositionStep(ctx, |
| 486 | trueCondition, |
| 487 | ctx.NewCall(operators.Conditional, |
| 488 | s.condition(), |
| 489 | ctx.NewCall("optional.of", s.expr()), |
| 490 | step.expr()), |
| 491 | ) |
| 492 | } |
| 493 | // The `step` is pruned away by a unconditional non-optional step `s`. |
| 494 | // Likely a candidate for dead-code warnings. |
| 495 | return s |
| 496 | } |
| 497 | return newNonOptionalCompositionStep(ctx, |
| 498 | trueCondition, |
| 499 | ctx.NewCall(operators.Conditional, |
| 500 | s.condition(), |
| 501 | s.expr(), |
| 502 | step.expr())) |
| 503 | } |
| 504 | |
| 505 | // newOptionalCompositionStep returns an output step with an optional policy output. |
| 506 | func newOptionalCompositionStep(ctx *cel.OptimizerContext, cond, out ast.Expr) optionalCompositionStep { |
nothing calls this directly
no test coverage detected