summaryrefslogtreecommitdiff
path: root/internal/rpn/variable.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-22 15:15:51 +0300
committerPaul Buetow <paul@buetow.org>2026-05-22 15:15:51 +0300
commitaad7a14067ef3ab960ab86185b6a36f9bf2231b8 (patch)
treed380f38d3ba7334f1107499933965d2b1592671f /internal/rpn/variable.go
parentcbeedd607f034ee57ed530556740dc37905791ea (diff)
refactor(rpn): split StringNum/Symbol out of Number interface (LSP fix)
StringNum and Symbol implemented Number but their Float64(), Compare(), Bool(), IsZero(), IsNegative(), and SetMetric() methods always returned errors. Any code accepting Number had to defensively check IsString()/IsSymbol() before arithmetic, defeating the interface. Split Number into two interfaces: - StackValue: base interface for anything on the stack (String, IsBool, IsString, IsSymbol, Metric) - NumericValue: embeds StackValue + arithmetic contract (Float64, IsZero, IsNegative, Compare, Bool, SetMetric) Float and Rat implement both; StringNum and Symbol implement StackValue only. Keep Number as a type alias for backward compat. Updated Stack, popStack/popTwo/popAll, toFloat64, resolveMetric, convertToBase, GetCurrentStack/SetCurrentStack, and all callers to use the correct interface level.
Diffstat (limited to 'internal/rpn/variable.go')
-rw-r--r--internal/rpn/variable.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/internal/rpn/variable.go b/internal/rpn/variable.go
index 6bde73d..79e5dd7 100644
--- a/internal/rpn/variable.go
+++ b/internal/rpn/variable.go
@@ -25,8 +25,8 @@ func (o *VariableOperations) AssignVariable(stack *Stack, name string) error {
return err
}
- // Convert Number to float64 for variable storage
- valF, err := val.Float64()
+ // Convert StackValue to float64 for variable storage
+ valF, err := toFloat64(val, "assigning variable")
if err != nil {
return fmt.Errorf("failed to get float64 value for variable: %w", err)
}