amber-lang / amber

💎 Amber the programming language compiled to bash

Home Page:https://amber-lang.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] exit in stdlib generate useless bash code

Mte90 opened this issue · comments

Right now the function is:

pub fun exit(code: Num): Null {
    unsafe $exit "{code}"$
}

In a function like:

if not is_root() {
    echo "This script requires root permissions!"
    exit(1)
}

Generate:

if [ $(echo '!' "$__AF_is_root66_v0__5_8" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
    echo "This script requires root permissions"'!'""
    exit__65_v0 1
    __AF_exit65_v0__7_5="$__AF_exit65_v0"
    echo "$__AF_exit65_v0__7_5" >/dev/null 2>&1
fi

My guess is that the function should be:

pub fun exit(code: Num): Null {
    silent unsafe $exit "{code}"$
}

No adding silent doesn't fix.

Maybe we can add a way to define a function that doesn't generate, like a comment/attribute:

__AF_exit65_v0__39_9="$__AF_exit65_v0"
echo "$__AF_exit65_v0__39_9" >/dev/null 2>&1