`delete` statement leaves its result on the stack

Open Beginner friendly
#92 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start with Action::stack_delta in crates/rascal/src/internal/as2_pcode/pcode.rs at the linked lines, then trace how codegen uses the deltas and truncate_stack for expression statements. Check the generated behavior for delete used as a statement against the reproduction in the issue; done when the loop visits a and b once each.

Written by the indexing model from the issue text.

Description

The result of a delete used as a statement is never popped. Inside a for..in loop, the leftover values get enumerated, so the loop doesn't end.

var o = {a: 1, b: 2};
var n = 0;
for (var k in o) {
    delete o.nothing;
    trace(k);
    if (++n == 5) {
        trace("too many iterations");
        break;
    }
}

Expected: a and b, once each.

Actual, in Flash Player (Rascal 0.3.6, SWF 8):

a
false
false
false
false
too many iterations

Assigning the result (var d = delete o.nothing;) works around it.

The cause seems to be the stack deltas in Action::stack_delta:

https://github.com/Dinnerbone/Rascal/blob/3f1a80c85dcc657cf4a67b72754b9c7869a6d9c5/crates/rascal/src/internal/as2_pcode/pcode.rs#L268-L269

Both actions push a boolean result, so these should be -1 (pops an object and a name) and 0 (pops a name). The codegen then believes the stack is already balanced, and truncate_stack emits no Pop for the expression statement.

Dominant language
Rust
Stars
22
Forks
2
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Dinnerbone/Rascal

All issues in Dinnerbone/Rascal

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.