This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #127333] add warning for until(assignment)
authorDan Collins <dcollinsn@gmail.com>
Tue, 7 Jun 2016 01:04:46 +0000 (21:04 -0400)
committerTony Cook <tony@develop-help.com>
Tue, 7 Jun 2016 04:43:48 +0000 (14:43 +1000)
commit0a44e30b028e9918e549705da4512ad5b5a98493
tree4d379ad0534bc61bf061c137825c177d6e656485
parent33d95a65610de4b893a90e38c300d3f0b0bf2fb0
[perl #127333] add warning for until(assignment)

while ($a = 1) emits a warning "Found = in conditional, should be ==".
However, until ($a = 1) does not. The parser breaks down until
(condition) into while (!(condition)), which defeats the check in
S_scalarboolean, since it is looking for a conditional that /is/ an
assignment, but we have a conditional that is a thinly veiled assignment.

A similar bug is [perl #127122]. That bug was fixed by treating
unless (a) {b} else {c} as if (a) {c} else {b}, instead of treating it
as if (!a) {b} else {c}. That approach will not work here.

Instead, the test in S_scalarboolean has been widened. It previously
looked for an OP_SASSIGN with op_first OP_CONST, it now also detects an
OP_NOT surrounding that construct.

Tests for both while() and until() were also added to t/lib/warnings/op.
op.c
t/lib/warnings/op