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.
()
| 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. |
| 82 | func (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. |
| 105 | type CompiledVariable struct { |