mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
f5eeb07bd2
This was previously done in several places in a somewhat convoluted way, which probably made sense at some point. As expected however, a few small local variations had emerged, and while nothing critical, this code wasn't very nice to work with. Some comments stated as the rationale for the design was avoiding allocations, but those were nowhere to be seen when measured now, meaning there was no good reason to have it remain this way! It was *quite* nice to be able to merge the numbers comparsion functions (in particular) together into one! We now have a unified way for comparing Number values throughout the AST package, and as an added bonus, `1.0 == 1` is now true consistently for Rego. See for example @srenatus example in https://github.com/open-policy-agent/opa/issues/4797 ``` $ opa eval -fpretty 'count({1.0, 1})' 2 ``` Doing the same now gives: ``` $ go run main.go eval -fpretty 'count({1.0, 1})' 1 $ go run main.go eval -fpretty 'count({1.0, 1, 1.000, 1.00000})' 1 ``` What I have left out for now is however _presentation_. Meaning that even though 1.0 and 1 is now treated as the same value, you may still see either '1' or 1.0' (or whatever) displayed, depending on what was parsed. Should be easy to fix, but could perhaps be perceived as surprising... so holding off on that until we've had a discussion on the topic. Signed-off-by: Anders Eknert <anders@eknert.com>