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

cgen: fix codegen for return on last statement of return IfExpr #23551

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

felipensp
Copy link
Member

Fix #23550

Copy link

Connected to Huly®: V_0.6-21979

@felipensp felipensp changed the title cgen: fix multi return on if expr cgen: fix codegen for return on last statement of return IfExpr Jan 22, 2025
@JalonSolov
Copy link
Contributor

So you're just making sure the return is output, rather than warning/error?

@felipensp
Copy link
Member Author

So you're just making sure the return is output, rather than warning/error?

Yes. Just like we do in return match foo { a { return expr } else { ... } }

@JalonSolov
Copy link
Contributor

I think that's a mistake as well. A return inside a return makes no sense.

@felipensp felipensp marked this pull request as ready for review January 22, 2025 20:10
@spytheman
Copy link
Member

I think that's a mistake as well. A return inside a return makes no sense.

It does make sense a bit, since in the if cond { expr1 } else { expr2 } form,
expr1 and expr2 can be compound expression lists, i.e. they may have statements (including logic ones, and early returns).

I do think that in many cases, such long if expressions, can become convoluted, and allow for bugs, but the language does allow them :-| .

@spytheman
Copy link
Member

spytheman commented Jan 23, 2025

In any case, unless they are banned, V should not produce garbage, that fails at runtime (the branch with the return was executed in the issue, but the output was not, what was returned, but empty values).

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit d9a2fb1 into vlang:master Jan 23, 2025
72 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.

return if statement broken returning optional multiple values.
3 participants