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

Method checkUnreachableCode

policy/compiler.go:449–469  ·  view source on GitHub ↗
(rule *CompiledRule, iss *cel.Issues)

Source from the content-addressed store, hash-verified

447}
448
449func (c *compiler) checkUnreachableCode(rule *CompiledRule, iss *cel.Issues) {
450 compiledMatches := rule.Matches()
451 matchCount := len(compiledMatches)
452 for i := matchCount - 1; i >= 0; i-- {
453 m := compiledMatches[i]
454 triviallyTrue := m.ConditionIsLiteral(types.True)
455
456 // If the match is a single output or a nested rule that always returns a value, it is
457 // exhaustive. If the condition is trivially true, then all subsequent branches are unreachable.
458 isExhaustive := triviallyTrue && (m.NestedRule() == nil || !m.NestedRule().HasOptionalOutput())
459 if isExhaustive && i != matchCount-1 {
460 if m.Output() != nil {
461 iss.ReportErrorAtID(m.SourceID(), "match creates unreachable outputs")
462 }
463 if m.NestedRule() != nil {
464 iss.ReportErrorAtID(m.NestedRule().SourceID(), "rule creates unreachable outputs")
465 }
466 break
467 }
468 }
469}
470
471func (c *compiler) relSource(pstr ValueString) *RelativeSource {
472 line := 0

Callers 1

compileRuleMethod · 0.95

Calls 7

ConditionIsLiteralMethod · 0.80
NestedRuleMethod · 0.80
HasOptionalOutputMethod · 0.80
ReportErrorAtIDMethod · 0.65
MatchesMethod · 0.45
OutputMethod · 0.45
SourceIDMethod · 0.45

Tested by

no test coverage detected