Last active
August 3, 2018 07:14
-
-
Save rurban/e7e3873613c4658bc552fba4356d7022 to your computer and use it in GitHub Desktop.
use warnings 'shadow-package'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# detected by mziescha | |
use warnings 'shadow-package'; # or just shadow | |
package Acme::Test; | |
sub new { bless {}, shift } | |
sub Sub { 'shadowed' } | |
package Acme::Test::Sub; | |
sub new { print 'Sub'; bless {}, shift } # warn: "Package Acme::Test::Sub shadowed by Acme::Test->Sub at warn-shadow-pkg.pl, line 8" | |
package main; | |
# calls &Acme::Test:: Sub, then ->new, not &Acme::Test::Sub -> new | |
Acme::Test::Sub->new(); # warn: "Subroutine &Acme::Test::Sub shadowed by Acme::Test->Sub at warn-shadow-pkg.pl, line 13" | |
=pod | |
Note that Acme::Test::Sub is written in package and subroutine syntax it is still | |
taken as static method call, overriding the existing package. | |
With use warnings 'shadow-package' or 'shadow' | |
warn about when | |
* adding a new package shadowed by an existing method (at compile-time) | |
* adding a method shadowing an existing package (at compile-time) | |
* calling a method shadowing an existing package-sub (at compile-time) | |
No warning at run-time? Or only when not already warned before. | |
This would be needed for computed method names, if it still shadows the package then. | |
tracked at https://github.com/perl11/cperl/issues/368 | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Open points:
In the calling case. Use which location? The callers location to see the wrong usage, or the definition of the shadower: file, line 6 or both? "&Acme::Test::Sub shadowed by Acme::Test->Sub defined at warn-shadow-pkg.pl, line 6 at warn-shadow-pkg.pl, line 13", na
name of the warning? it should be in the shadow category. so when you
use warnings 'shadow';
it should be enabled.the other case of shadow warnings would be variables being shadowed. These are not so severe as packages.
compile-time only, or also at run-time? In C such warnings are compile-time only (of course). But compile-time only would miss all the cases with computed method-names, which could also be shadowed.
Tracked at perl11/cperl#368