niieani / bash-oo-framework

Bash Infinity is a modern standard library / framework / boilerplate for Bash
https://github.com/niieani/bash-oo-framework/discussions
MIT License
5.57k stars 247 forks source link

False boolean not working #82

Open jasontcs opened 5 years ago

jasontcs commented 5 years ago

The following error occurred

boolean trueVar=true $var:trueVar toString #true

boolean falseVar=false $var:falseVar toString #UNCAUGHT EXCEPTION: toString

Is it a bug? Or is my implementation incorrect?

niieani commented 5 years ago

Actually toString of false boolean is implemented so that it behaves like false:

https://github.com/niieani/bash-oo-framework/blob/0276ffad26cabd5ce29f18b4ca87fbc01bc630ab/lib/TypePrimitives/boolean.sh#L15

The return code of false is 1, which means it's treated like an exception.

Probably might sense to change how boolean toString works cause it's unintuitive right now. I don't remember what was the reason I did it like this. I think it's so that invoking that variable would behave similarly to invoking true or false and so that one could use this in comparisons or logic.