You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling the same function more then once as an argument to another function, the return value of the function seems to get overwritten by the last function call.
Example:
fun double(n: Num): Num {
return n * 2
}
fun add(a: Num, b: Num): Num {
return a + b
}
echo add(double(2), double(3))
// Expected output: 4 + 6 == 10
// Actual output: 6 + 6 == 12
Compiled bash code:
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
function double__0_v0 {
local n=$1
__AF_double0_v0=$(echo ${n} '*' 2 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
function add__1_v0 {
local a=$1
local b=$2
__AF_add1_v0=$(echo ${a} '+' ${b} | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
double__0_v0 2;
__AF_double0_v0__9=$__AF_double0_v0;
double__0_v0 3;
__AF_double0_v0__9=$__AF_double0_v0;
add__1_v0 $__AF_double0_v0__9 $__AF_double0_v0__9;
__AF_add1_v0__9=$__AF_add1_v0;
echo $__AF_add1_v0__9
This is because the same variable __AF_double0_v0__9 is used to store both of the function calls in this case.
The text was updated successfully, but these errors were encountered:
Environment:
When calling the same function more then once as an argument to another function, the return value of the function seems to get overwritten by the last function call.
Example:
Compiled bash code:
This is because the same variable
__AF_double0_v0__9
is used to store both of the function calls in this case.The text was updated successfully, but these errors were encountered: