Skip to content

zend_compile: Allow (void) in for’s initializer and loop expression #18303

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

Merged
merged 2 commits into from
Apr 14, 2025

Conversation

TimWolla
Copy link
Member

The initializer and loop expression of a for() loop only accept expressions, but they act like statements in spirit - their results are completely ignored. Allow (void) there to allow suppressing #[\NoDiscard], since there is no semantic ambiguity of what (void) returns anyways.

Fixes #18301


/cc @edorian

The initializer and loop expression of a `for()` loop only accept expressions,
but they act like statements in spirit - their results are completely ignored.
Allow `(void)` there to allow suppressing `#[\NoDiscard]`, since there is no
semantic ambiguity of what `(void)` returns anyways.

Fixes php#18301
Copy link
Member

@DanielEScherzer DanielEScherzer left a comment

Choose a reason for hiding this comment

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

Looks correct as far as I understand

@TimWolla TimWolla merged commit 9ac8820 into php:master Apr 14, 2025
9 checks passed
@TimWolla TimWolla deleted the void-cast-for-expression branch April 14, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[NoDiscard] and (void) - some errors cannot be ignored
2 participants