From d1fbef4cb7fb51c519058d2c91f4f667bc7b9658 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 25 Jun 2024 16:08:00 -0400 Subject: return error if not enough operands in stack --- calc.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/calc.go b/calc.go index e9b46d1..25756fc 100644 --- a/calc.go +++ b/calc.go @@ -69,10 +69,9 @@ func (c *Calculator) performOperation(operator byte) error { // operands returns the left and right operands, or error if there are not enough. func (c *Calculator) operands() (lhs, rhs float64, err error) { - if buf, err := c.parseBuffer(); err == nil { - rhs = buf + if rhs, err := c.parseBuffer(); err == nil { lhs, err = c.stack.pop() - return lhs, rhs, nil + return lhs, rhs, err } else if stk, err := c.stack.pop(); err == nil { rhs = stk if lhs, err = c.stack.pop(); err == nil { -- cgit v1.2.3