Moderocky/ByteSkript

Nested loops don't balance file tree correctly

Closed this issue · 5 comments

Describe the bug
When a loop is nested within another section (the length of the sections array in the context is 2 or more), the loop fails to balance the file tree at section exit. This is due to a mismatch between the owner metadata assigned to the tree by the loop section and the owner metadata it expects when exiting

To Reproduce
Steps to reproduce the behavior:

  1. Load this script:
on script load:
  trigger:
    if 1 is 1:
      set {ctr} to 0

      // Any section that builds the tree with context.getSection(1) and exits expecting context.getSection()
      // to be the owner of the tree causes the exception. Affects at least While, LoopTimes, and LoopIn.
      while {ctr} is less than 10:
        add 1 to {ctr}
  1. Notice ScriptCompileError: Unable to balance ___ flow tree. (Line 9)

Expected behaviour
The script should compile and effectively be a no-op, since no visual output is given.

Additional Context
I'm using ByteSkript v1.0.21.

This appears to be two bugs coinciding, IF-trees aren't closing correctly because they're expecting an ELSE and some use the wrong section retrieval method.

I've partially fixed the IF-problem but I'm missing a tree somewhere.

I'll be home in roughly 3½ hours, I can probably use IDEA's debugger to investigate further.

I fixed it, but your code is wrong anyway because add isn't actually used for maths operations currently.

This is, for some reason, causing the error that you actually had. I honestly have no idea how or why but if you change it to the correct thing it balances fine.

Fixed in .22