Skip to content

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