MCPcopy Create free account
hub / github.com/cel-expr/cel-go / HasOptionalOutput

Method HasOptionalOutput

policy/compiler.go:71–88  ·  view source on GitHub ↗

HasOptionalOutput returns whether the rule returns a concrete or optional value. The rule may return an optional value if all match expressions under the rule are conditional.

()

Source from the content-addressed store, hash-verified

69// HasOptionalOutput returns whether the rule returns a concrete or optional value.
70// The rule may return an optional value if all match expressions under the rule are conditional.
71func (r *CompiledRule) HasOptionalOutput() bool {
72 optionalOutput := false
73 for _, m := range r.Matches() {
74 if m.NestedRule() != nil && m.NestedRule().HasOptionalOutput() {
75 // If the nested rule is unconditional, the matching may fallthrough to the next match
76 // in this context (unwrapping the optional value from the nested rule).
77 if !m.ConditionIsLiteral(types.True) {
78 return true
79 }
80 optionalOutput = true
81 } else if m.ConditionIsLiteral(types.True) {
82 return false
83 } else {
84 optionalOutput = true
85 }
86 }
87 return optionalOutput
88}
89
90// CompiledVariable represents the variable name, expression, and associated type-check declaration.
91type CompiledVariable struct {

Callers 3

optimizeRuleMethod · 0.80
checkUnreachableCodeMethod · 0.80

Calls 3

MatchesMethod · 0.95
NestedRuleMethod · 0.80
ConditionIsLiteralMethod · 0.80

Tested by 1