amber-lang / amber

💎 Amber the programming language compiled to Bash
https://amber-lang.com
GNU General Public License v3.0
3.94k stars 89 forks source link

[BUG] Concate value on print generate wrong bash #427

Open Mte90 opened 3 months ago

Mte90 commented 3 months ago

An example code:

pub fun round(number: Num): Num {
    let operator = "+"
    if number > 0 {
        operator = "-"
    }

    return unsafe $echo "({number}{operator}0.5)/1" | bc$ as Num
}

Generates:

round__1_v0() {
    local number=$1
    local operator="+"
    if [ $(echo ${number} '>' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
        operator="-"
    fi
    __AMBER_VAL_0=$(echo "(${number}0.5)/1" | bc${operator})
    __AS=$?
    __AF_round1_v0="${__AMBER_VAL_0}"
    return 0
}
b1ek commented 3 months ago

so.. what's the problem?

Mte90 commented 3 months ago

The line:

    __AMBER_VAL_0=$(echo "(${number}0.5)/1" | bc${operator})

Is wrong.

It should be:

    __AMBER_VAL_0=$(echo "(${number}${operator}0.5)/1" | bc)
b1ek commented 3 months ago

huh.. that is like super weird

Ph0enixKM commented 3 months ago

I think I know what's the problem and how to fix it. But I have to test it first on my machine