(rule *CompiledRule, iss *cel.Issues)
| 447 | } |
| 448 | |
| 449 | func (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 | |
| 471 | func (c *compiler) relSource(pstr ValueString) *RelativeSource { |
| 472 | line := 0 |
no test coverage detected