[bug] Variables modified inside expressions don't behave correctly · Issue #180 · mlogjs/mlogjs · GitHub
Skip to content

[bug] Variables modified inside expressions don't behave correctly #180

Open

Description

@JeanJPNM

I watched this youtube video and noticed that the bug also affects mlogjs.

If we compile the following code and compare its output to the equivalent code in a browser, we see that they diverge:

let a = 1
print(a + ++a);
printFlush();

Generated code:

set a:1:4 1
op add a:1:4 a:1:4 1
op add &t0 a:1:4 a:1:4
print &t0
printflush message1

If we run the equivalent code on the browser, the answer we get is 3, but when running the generated code the answer is 4.

One way to fix this is to make mlogjs create a "security copy" of each value that goes into an expression and remove unused copies.
The first part is trivial (look at #115 and #116) but removing the unused ones requires a rework on the compiler to perform optimizations on an intermediate representation.

Activity

  1. changed the title [-][bug[/-] [+][bug] Variables modified inside expressions don't behave correctly[/+] on Jun 6, 2023
  2. added this to the v0.7 milestone on Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions