Skip to content
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

[LUA] Fix do while loops on lua #11807

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

NeeEoo
Copy link
Contributor

@NeeEoo NeeEoo commented Oct 29, 2024

This fixes an issue where

var test = null;

do {
    test = {type: 5};
}
while (test.type != 5);

would crash

@Raltyro
Copy link

Raltyro commented Oct 30, 2024

why did it need to have first vsriable anyway

@Simn
Copy link
Member

Simn commented Oct 30, 2024

A test would be good!

@skial skial mentioned this pull request Oct 31, 2024
1 task
@jdonaldson
Copy link
Member

It looks like you just changed the order of the elements in the "or" clause:

while (cond or _hx_do_first_x)

to

while(_hx_do_first_x or cond)

What's the reason why the order matters?

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Nov 2, 2024

It looks like you just changed the order of the elements in the "or" clause:


while (cond or _hx_do_first_x)

to


while(_hx_do_first_x or cond)

What's the reason why the order matters?

Because if the loop expression depends on something to be changed in the loop it breaks.

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Nov 2, 2024

Basically it doesn't need to run the conditional expression, thus if the expression has code that depends on one iteration of the loop to run then it wont crash.

Do while loops in other languages only runs the conditional expression after the loop has run once, and if it returns true it goes back to the beginning. Replicating this behavior on lua means the _hx_do_first_x has to be at the start, so the entire condition doesn't run.

@jdonaldson
Copy link
Member

jdonaldson commented Nov 7, 2024

This seems like it might be unspecified behavior. I think a test would be a good idea to make sure the other targets have the same behavior. If all targets work the same I think it's a good change.

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Dec 12, 2024

This seems like it might be unspecified behavior. I think a test would be a good idea to make sure the other targets have the same behavior. If all targets work the same I think it's a good change.

are there any guides on making a test?

@Simn
Copy link
Member

Simn commented Dec 12, 2024

You can copy some issue test from https://github.com/HaxeFoundation/haxe/tree/development/tests/unit/src/unit/issues, it should be somewhat straightforward from there.

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Dec 13, 2024

There tests working!

@NeeEoo
Copy link
Contributor Author

NeeEoo commented Dec 13, 2024

I tested it without the fix and only lua crashed, so this seems to work for every other platform thats currently in actions! So thats good!

@Simn Simn merged commit 52d1bdd into HaxeFoundation:development Dec 16, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants