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

weird error in foreach loop #22

Open
AdamMil opened this Issue Jan 24, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@AdamMil
Copy link

AdamMil commented Jan 24, 2019

Try compiling this function.

function foo() {
  foreach(o in list) {
    if (a) { continue; }
    b.push();
  }
}

Then decompile it. You get this result:

function foo() {
  foreach(o in list) {
    if (a) { continue; }
    a.push();
  }
}

In fact, whatever the condition of the 'if' is will be duplicated on the next line. E.g.

if (a.query(1,2,3)) { continue; }
b.push();

becomes:

if (a.query(1,2,3)) { continue; }
a.query(1,2,3).push();

when it's placed inside the foreach loop.

@AdamMil

This comment has been minimized.

Copy link
Author

AdamMil commented Jan 24, 2019

I believe it's because this code in DecompileLoopJumpInstruction can skip ahead even when the current op is not OP_LINE.

bool bHasLineInfo = !m_LineInfos.empty();
...
if (bHasLineInfo) // skip OP_LINE
    state.NextInstruction();

I tried adding another check:

bool bHasLineInfo = !m_LineInfos.empty() && m_Instructions[state.IP()].op == OP_LINE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment