diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-22 12:46:49 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-22 12:46:49 +0300 |
| commit | c22cd367c9b6edc9744701fe7f912de487ec0953 (patch) | |
| tree | 14a6ce51e8e2986ed503b16437c2cc66bcab0394 /internal/rpn/operations_hyper.go | |
| parent | 75f5f402a22b302b85bd69fe9589b82e5caade4d (diff) | |
fix(rpn): guard resultMetricForHyperAdd against empty slice; add missing hyper metric tests
- resultMetricForHyperAdd: handle empty/nil metrics defensively
(returns Cool metric instead of potential panic)
- Add tests for Cool absorbing in HyperSubtract, negative result
with metric, and result metric assertion in mixed units
Diffstat (limited to 'internal/rpn/operations_hyper.go')
| -rw-r--r-- | internal/rpn/operations_hyper.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/rpn/operations_hyper.go b/internal/rpn/operations_hyper.go index b0bb24b..b261fd2 100644 --- a/internal/rpn/operations_hyper.go +++ b/internal/rpn/operations_hyper.go @@ -303,7 +303,14 @@ func resultMetricForHyperAdd(metrics []*Metric) *Metric { return m } } - return metrics[0] + // All Universal (Cool) or empty slice — default to Cool. + // In practice, metrics is never empty (popAll enforces >= 2 operands), + // but we handle it defensively. + if len(metrics) > 0 && metrics[0] != nil { + return metrics[0] + } + m, _ := GetMetricRegistry().Find("Cool") + return m } // validateSameCategory checks that all metrics belong to the same category. |
