Skip to content

5.41.4: B::Deparse generates code which emits "Possible precedence problem between ! and numeric eq (==)" warning #22661

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

Closed
eserte opened this issue Oct 12, 2024 · 1 comment
Labels

Comments

@eserte
Copy link
Contributor

eserte commented Oct 12, 2024

Module: B::Deparse

Description
!$something == $else throws warnings with perl 5.41.x. B::Deparse may generate code which triggers this warning.

Steps to Reproduce
Sample oneliner:

$ perl5.41.4 -w -MO=Deparse -e 'my $p; if ((!$p) == 1) { }' | perl5.41.4 -cw
-e syntax OK
Possible precedence problem between ! and numeric eq (==) at - line 3.
- syntax OK

Output produced by B::Deparse is here:

BEGIN { $^W = 1; }
my $p;
if (!$p == 1) {
    ();
}
-e syntax OK

Expected behavior
B::Deparse should not drop the parentheses in this example

Perl configuration

Seen with normally compiled 5.41.4

@jkeenan
Copy link
Contributor

jkeenan commented Oct 15, 2024

Module: B::Deparse

Description !$something == $else throws warnings with perl 5.41.x. B::Deparse may generate code which triggers this warning.

Steps to Reproduce Sample oneliner:

$ perl5.41.4 -w -MO=Deparse -e 'my $p; if ((!$p) == 1) { }' | perl5.41.4 -cw
-e syntax OK
Possible precedence problem between ! and numeric eq (==) at - line 3.
- syntax OK

[snip]

@mauke, do you have thoughts on this problem?

mauke added a commit to mauke/perl5 that referenced this issue Oct 15, 2024
Since 570fa43, we emit precedence warnings if the LHS of a comparison
or binding op starts with an unparenthesized logical negation (`!`, as
in `!$x == $y`). Explicit parens can be used to avoid the warning
(`(!$x) == $y`).

Teach B::Deparse to keep these parentheses even if they're not strictly
required by operator precedence because we don't want the deparsed code
to generate more warnings than the original code.

Fixes Perl#22661.
@mauke mauke added Bug and removed Needs Triage labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants