lmorg / murex

A smarter shell and scripting environment with advanced features designed for usability, safety and productivity (eg smarter DevOps tooling)
https://murex.rocks
GNU General Public License v2.0
1.42k stars 29 forks source link

`expr` behaves inconsistently when invoked directly vs with `=` (deprecated) #827

Open tiymat opened 1 week ago

tiymat commented 1 week ago

Describe the bug: Invoking expr via expr gives different results than invoking it with = or just writing the expression.

Expected behaviour: Invoking an expression by any of the 3 possible ways should provide the same result.

Screenshots: image

Platform (please complete the following information):

Additional context Bracketing the expression seems to fix the issue as a workaround. e.g. expr (1 + 2) gives 3.

lmorg commented 1 week ago

The = syntax is old code where I relied on a 3rd party module to handle expressions. However because the syntax for = and expr differs slightly (where I was able to make improvements to Murex's parser to natively support expressions), it meant I was nervous about replacing = with the new code as it would cause braking changes. But the = code is now deprecated and will be removed in the next major release of Murex.

expr wasn't intended to be invoked manually because there's some special-case code handling parsing of expressions to make them more ergonomic, and that always doesn't translate well to statements. This is something I should update the docs to reflect.

That all said, the issue you ran into was definitely a bug because expr was only checking the first parameter. That's now fixed in develop

tiymat commented 1 week ago

Thanks for the fix! The specific part of the documentation that led to me trying it was the last example of the Usage block in the expr reference. image

lmorg commented 1 week ago

@tiymat that's a very good point. Is the new docs (only in develop at the moment) any clearer? https://dev.murex.rocks/commands/expr.html#description

tiymat commented 1 week ago

@tiymat that's a very good point. Is the new docs (only in develop at the moment) any clearer? https://dev.murex.rocks/commands/expr.html#description

Definitely!