Skip to content

[Bug Report] Buggy visualization for variables going out of scope #61

@jetline0

Description

@jetline0

Describe the bug
The visualizer is inconsistent in how it visualizes variables going out of scope. In some instances, a variable going out of scope will be treated as such and will disappear once the visualizer steps out of the block the variable was defined in. In other cases, like in our example with a for loop, the variable persists after the block is exited.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the visualizer
  2. Paste the following code snippet:
int main(){
    int a = 0;
    for (int b = 0; b < 1; b++){
        int c = 15150;
        a++;
    }
    int b = 1;
    return 0;
}
  1. Compile the program
  2. Step through the program and notice how c will persist after the for loop

Expected behavior
We expect c to not be in scope after the for loop exits.

Here is a program that works as expected:

int main(){
    int a = 0;
    if (a == 0) {
        int x = 5;
    }
    int b = 1;
    return 0;
}

where x will not be in scope after the line int b = 1; is executed.

Screenshots
Failing program:
image

Sample working program:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions