Open
Description
In a recursive subroutine, when trying to set value at specified index in an array, OSTW "forgets" to include current stack size in the generated Workshop action.
Based on the following OSTW recursive subroutine:
recursive void Sub() "" {
Any[] arr = [];
Any val = 0;
val = 1;
arr[0] = 1;
val += 1;
arr += 1;
}
The following actions are generated:
Modify Global Variable(val, Append To Array, 0);
Modify Global Variable(arr, Append To Array, Empty Array);
Global.val[Count Of(Global.val) - 1] = 1;
Global.arr[0] = 1;
Global.val[Count Of(Global.val) - 1] += 1;
Modify Global Variable At Index(arr, Count Of(Global.arr) - 1, Append To Array, 1);
Modify Global Variable(val, Remove From Array By Index, Count Of(Global.val) - 1);
Modify Global Variable(arr, Remove From Array By Index, Count Of(Global.arr) - 1);
Compare 3rd and 4th actions:
3. Global.val[Count Of(Global.val) - 1] = 1;
4. Global.arr[0] = 1;
The 3rd one correctly adds 1
to the stack.
The 4th one doesn't, and instead it just inserts item at the specified index directly in the stack, breaking it.
Appending item to an array with the +=
operator generates correct code:
Modify Global Variable At Index(arr, Count Of(Global.arr) - 1, Append To Array, 1);
Issue persists regardless whether c_style_workshop_output
is enabled or not.
Metadata
Metadata
Assignees
Labels
No labels