Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting value in array at index in a recursive subroutine forgets to include stack size #512

Open
PatrickSzela opened this issue Jan 8, 2025 · 0 comments

Comments

@PatrickSzela
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant