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

Code generated for a next in a while is incorrect #1337

Closed
herwinw opened this issue Oct 13, 2023 · 0 comments · Fixed by #1439
Closed

Code generated for a next in a while is incorrect #1337

herwinw opened this issue Oct 13, 2023 · 0 comments · Fixed by #1439
Labels
bug Something isn't working

Comments

@herwinw
Copy link
Member

herwinw commented Oct 13, 2023

Given this code:

a = 3
until a.negative?
  a -= 1
  next if a == 1
  p "a = #{a}"
end

p a

Cruby has the following output:

"a = 2"
"a = 0"
"a = -1"
-1

Natalie stops as soon as the next is hit:

"a = 2"

The code generated looks like this:

env->set_line(4);
auto send_6 =  a_var.public_send(env, symbols[3]/*:==*/, Args({ Value::integer(1) }, false), nullptr, self);
Value if_result7;
if (send_6->is_truthy()) {
    return Value(NilObject::the());
    if_result7 = Value(NilObject::the());
} else {
    if_result7 = Value(NilObject::the());
}

The return in the truthy path is not what we need.

@herwinw herwinw added the bug Something isn't working label Oct 13, 2023
herwinw added a commit to herwinw/natalie that referenced this issue Oct 13, 2023
This pattern does not work as expected in Natalie, see
natalie-lang#1337 for the bug report.
herwinw added a commit to herwinw/natalie that referenced this issue Oct 13, 2023
This pattern does not work as expected in Natalie, see
natalie-lang#1337 for the bug report.
herwinw added a commit to herwinw/natalie that referenced this issue Oct 14, 2023
This pattern does not work as expected in Natalie, see
natalie-lang#1337 for the bug report.
seven1m added a commit that referenced this issue Nov 4, 2023
seven1m added a commit that referenced this issue Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant