-
Notifications
You must be signed in to change notification settings - Fork 538
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 error in strict subs when the unary minus operator is applied on a bareword #17822
Comments
This is a feature: https://perldoc.pl/perlop#Symbolic-Unary-Operators |
(The reason |
This does not mention
No mention of the unary minus operator here, so that one should expect a compile-time error. |
This exception is deliberate, the parser explicitly turns off the flag ( This exception was introduced in it's current form in 7a52d87, before that the exception was done during tokenization. I've opened PR #17849 which documents this additional exception. |
Well, I don't see the point of this exception. It is surprising and can leave errors unnoticed. I wonder why anyone would use this "feature" in usual code. |
@vinc17fr it is used in quite a few very popular CPAN modules, like Moose and Tk. use Moose -meta_name => "my_meta";
my $txt = $main_window->Scrolled ("ROText" =>
-scrollbars => "e",
-wrap => "word",
-width => 70,
-height => 30,
-font => "{DejaVu Sans} 10",
-setgrid => 1,
-highlightthickness => 0,
-padx => 4,
-pady => 2,
-takefocus => 0,
)->grid (-sticky => "nsew"); Removing this feature would break a lot of CPAN and make an aweful lot of users very very unhappy |
This won't affect such a code as barewords are already allowed before #!/usr/bin/env perl
use strict;
my %h = (foo => 0);
foo; accepts #!/usr/bin/env perl
use strict;
my %h = (-foo => 0);
-foo; should still accept |
It is also used throughout the Mojolicious ecosystem, Type::Tiny, App::Cmd, Gtk2, Data::Section, Smart::Comments, HTML::TreeBuilder, and these are just the things I found up to the letter C when looking for instances directly followed by a semicolon. It's not necessarily a good idea, because having a symbol defined before using it will parse as that symbol instead of a string unlike with the following fat comma, but it's not possible to change. |
Module:
Description
In strict subs, when the unary minus operator is applied on a bareword, perl does not issue any error.
Steps to Reproduce
perl -e 'use strict "subs"; my $x = -foo;'
Expected behavior
One does not get any error, while one should have got an error just like with:
perl -e 'use strict "subs"; my $x = foo;'
and
perl -e 'use strict "subs"; my $x = -foo**2;'
Perl configuration
The text was updated successfully, but these errors were encountered: