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

Method HasOptionalOutput

policy/compiler.go:82–102  ·  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

80// HasOptionalOutput returns whether the rule returns a concrete or optional value.
81// The rule may return an optional value if all match expressions under the rule are conditional.
82func (r *CompiledRule) HasOptionalOutput() bool {
83 if r.semantic == aggregate {
84 return false
85 }
86 optionalOutput := false
87 for _, m := range r.Matches() {
88 if m.NestedRule() != nil && m.NestedRule().HasOptionalOutput() {
89 // If the nested rule is unconditional, the matching may fallthrough to the next match
90 // in this context (unwrapping the optional value from the nested rule).
91 if !m.ConditionIsLiteral(types.True) {
92 return true
93 }
94 optionalOutput = true
95 } else if m.ConditionIsLiteral(types.True) {
96 return false
97 } else {
98 optionalOutput = true
99 }
100 }
101 return optionalOutput
102}
103
104// CompiledVariable represents the variable name, expression, and associated type-check declaration.
105type CompiledVariable struct {

Callers 3

optimizeRuleMethod · 0.80
checkUnreachableCodeMethod · 0.80

Calls 3

MatchesMethod · 0.95
NestedRuleMethod · 0.80
ConditionIsLiteralMethod · 0.80

Tested by 1