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
Describe the bug
If a function declares a variable by reference, but an identically named variable exists in another scope, the value is not returned correctly.
N.B. This only seems to be a problem with passing array variables by reference.
To Reproduce
Run the following script to reproduce:
$ cat ref.ab
#!/usr/bin/env amber
fun set_ref(ref numbers: [Num]): Null {
echo "In fun before set: {numbers}"
numbers = [4, 5, 6]
echo "In fun after set: {numbers}"
}
main {
let numbers = [1, 2, 3]
echo "In main before call: {numbers}"
set_ref(numbers)
echo "In main after call: {numbers}"
}
$ ./ref.ab
In main before call: 1 2 3
In fun before set: numbers // <======== Expected "1 2 3"
In fun after set: 4 5 6
In main after call: 1 2 3 // <========= Expected "4 5 6"
Expected behavior
The script above should behave as it does if a different variable name is used:
$ cat ref.ab
#!/usr/bin/env amber
fun set_ref(ref byref: [Num]): Null {
echo "In fun before set: {byref}"
byref = [4, 5, 6]
echo "In fun after set: {byref}"
}
main {
let numbers = [1, 2, 3]
echo "In main before call: {numbers}"
set_ref(numbers)
echo "In main after call: {numbers}"
}
$ ./ref.ab
In main before call: 1 2 3
In fun before set: 1 2 3
In fun after set: 4 5 6
In main after call: 4 5 6
Additional context
N/A
The text was updated successfully, but these errors were encountered:
Yep, that would do it; the_bug is the same in both function and main block. I don't think it's worth trying to fix anything until @Ph0enixKM has done his translation layer thingy though.
Describe the bug
If a function declares a variable by reference, but an identically named variable exists in another scope, the value is not returned correctly.
N.B. This only seems to be a problem with passing array variables by reference.
To Reproduce
Run the following script to reproduce:
Expected behavior
The script above should behave as it does if a different variable name is used:
Additional context
N/A
The text was updated successfully, but these errors were encountered: