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

strict does not ban all barewords #16838

Open
p5pRT opened this issue Feb 4, 2019 · 7 comments
Open

strict does not ban all barewords #16838

p5pRT opened this issue Feb 4, 2019 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 4, 2019

Migrated from rt.perl.org#133823 (status was 'open')

Searchable as RT133823$

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2019

From wagnerc@plebeian.com

Using the strict pragma does not ban all usages of barewords or force
them to resolution as subroutines so that they can fail as an undefined
subroutine.

Tested on Perl 5.22.4 and 5.29.8

Examples​:
$ perl -MO=Deparse,-p,-q,-x20,-P -e 'use strict; print "$^X $^V\n"; my
$string; print split FOO, $string; '
use strict;
print(((($^X . ' ') . $^V) . "\n"));
my($string);
print(split(/FOO/, $string, 0));
-e syntax OK

$ perl -MO=Deparse,-p,-q,-x20,-P -e 'use strict; print "$^X $^V\n"; my
@​list; print sort FOO @​list; '
use strict;
print(((($^X . ' ') . $^V) . "\n"));
my(@​list);
print((sort FOO @​list));
-e syntax OK

Thanks.

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2019

From @tonycoz

On Mon, 04 Feb 2019 15​:16​:24 -0800, wagnerc@​plebeian.com wrote​:

Using the strict pragma does not ban all usages of barewords or force
them to resolution as subroutines so that they can fail as an undefined
subroutine.

Tested on Perl 5.22.4 and 5.29.8

Examples​:
$ perl -MO=Deparse,-p,-q,-x20,-P -e 'use strict; print "$^X $^V\n"; my
$string; print split FOO, $string; '
use strict;
print(((($^X . ' ') . $^V) . "\n"));
my($string);
print(split(/FOO/, $string, 0));
-e syntax OK

$ perl -MO=Deparse,-p,-q,-x20,-P -e 'use strict; print "$^X $^V\n"; my
@​list; print sort FOO @​list; '
use strict;
print(((($^X . ' ') . $^V) . "\n"));
my(@​list);
print((sort FOO @​list));
-e syntax OK

split is fixed by my patch in #133822.

sort specially allows for a bareword subname for the sort sub and dies at runtime if the sub named doesn't exist, even if the sub doesn't need to be called​:

$ ./perl -Ilib -e 'use strict; my @​list; print sort FOO @​list; '
Undefined sort subroutine "main​::FOO" called at -e line 1.

Tony

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2019

From @Grinnz

On Mon, 04 Feb 2019 21​:09​:43 -0800, tonyc wrote​:

sort specially allows for a bareword subname for the sort sub and dies
at runtime if the sub named doesn't exist, even if the sub doesn't
need to be called​:

$ ./perl -Ilib -e 'use strict; my @​list; print sort FOO @​list; '
Undefined sort subroutine "main​::FOO" called at -e line 1.

Not entirely true. See #36333, #130178, #133138.

-Dan

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2019

From @Grinnz

On Tue, 05 Feb 2019 00​:13​:43 -0800, grinnz@​gmail.com wrote​:

Not entirely true. See #36333, #130178, #133138.

Last one should be #133178

-Dan

@p5pRT
Copy link
Author

p5pRT commented Feb 5, 2019

From wagnerc@plebeian.com

The behavior of sort() is especially aberrant.

I found an even older ticket! https://rt-archive.perl.org/perl5/Ticket/Display.html?id=3629

This is surely the source of many sideways bugs.

Why doesn't sort() require the & character to name a sorting subroutine just like every other grab of a subroutine?
exists &foo;
defined &foo;
goto &foo;

sort &foo @​list;

@Grinnz
Copy link
Contributor

Grinnz commented Oct 21, 2019

Referenced issues: #2305, #7979, #15733, #16548

@xenu xenu removed the Severity Low label Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants