Skip Menu |
Report information
Id: 127206
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: util <bruce.gray [at] acm.org>
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



CC: Robert Bruce Gray III <bruce.gray [...] acm.org>
To: rakudobug [...] perl.org
From: Bruce Gray <bruce.gray [...] acm.org>
Subject: [BUG] Missing warning: assignment from constant RHS in conditional.
Date: Thu, 7 Jan 2016 16:07:35 -0600
Download (untitled) / with headers
text/plain 2.1k
Summary: The useful warning in Perl 5: Found = in conditional, should be == at ... is absent in Rakudo. Although its omission was originally intentional, the warning can be added to Rakudo in a more restricted form, catching most of the programmer errors that the Perl 5 warning caught, while still allowing valid code without complaint. $ perl6 --version This is Rakudo version 2015.12-140-gf1dd491 built on MoarVM version 2015.12 implementing Perl 6.c. $ perl6 -e 'my $foo = 3; if $foo = 4 { say "overwrote!" }; say $foo;' overwrote! 4 $ perl -wE 'my $foo = 3; if ($foo = 4) { say "overwrote!" }; say $foo;' Found = in conditional, should be == at -e line 1. overwrote! 4 http://irclog.perlgeek.de/perl6/2016-01-07#i_11848637 < Util> m: my $foo = 3; if $foo = 4 { say 'overwrote!' }; say $foo; <+camelia> rakudo-moar ed6ec7: OUTPUT«overwrote!␤4␤» < Util> In Perl 5, with warnings enabled, I would have been warned: < Util> Found = in conditional, should be == at ... < Util> Rakudo does not give this warning. Is this just NYI, or deliberate? < TimToady> deliberate < diakopter> I would think it should warn if it's a constant being assigned, but not otherwise < diakopter> non-True constant < diakopter> *True constant < TimToady> yes, we could warn if the RHS is constant < Util> TimToady: The lack of warning surprised me. < Util> I am following up for a member of Atlanta.pm, who was bitten by this change < Util> during early Perl 6 experimenting. * TimToady finds the spurious warning to be irritating on something like: while $this = getnextone() { ... } < TimToady> though there's less excuse for that construct in Perl 6 than in Perl 5 < Util> TimToady: but you have given us: while getnextone() -> $this { ... } < TimToady> since we can write: while getnextone() -> $this { ... } < TimToady> otoh, what if you want the final $this after the loop? < TimToady> and the failure mode of 'always true' is usually pretty obvious < TimToady> so I tend to approach this one from the side of "don't rule out valid code" < Util> 'always false' looks obvious too < Util> +1 on "don't rule out valid code". < Util> "warn if the RHS is constant" would catch many errors. — Thank you, Bruce Gray (Util on IRC)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org