oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

Consider word expansion before arithmetic parsing, e.g. $(( $x * 3 )) #2066

Open andychu opened 2 months ago

andychu commented 2 months ago

Aidan noticed a case where our static parsing philosophy is leading to the wrong result:

https://oilshell.zulipchat.com/#narrow/stream/121539-oil-dev/topic/ArithSub.20evaluation.20bug.20in.20autotools.20configure

Right now I think we will fix the more immediate autoconf issue, but this more general issue may come up later ...

$ dash -c 'x="1 + 2"; echo $(( $x * 3 ))'
7
$ zsh -c 'x="1 + 2"; echo $(( $x * 3 ))'
7
$ mksh -c 'x="1 + 2"; echo $(( $x * 3 ))'
7
$ yash -c 'x="1 + 2"; echo $(( $x * 3 ))'
7

OSH gives 9! Bad!

PossiblyAShrub commented 2 months ago

Some spec tests for this divergence were added in #2070.