Skip to content
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

Missing warning: assignment from constant RHS in conditional. #5018

Open
p6rt opened this issue Jan 7, 2016 · 1 comment
Open

Missing warning: assignment from constant RHS in conditional. #5018

p6rt opened this issue Jan 7, 2016 · 1 comment
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 7, 2016

Migrated from rt.perl.org#127206 (status was 'new')

Searchable as RT127206$

@p6rt
Copy link
Author

p6rt commented Jan 7, 2016

From @Util

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)

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant