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
Perl produces silly and repetitive warnings for nonexistent packages in @ISA #11259
Comments
From @demerphqCreated by @demerphqThis is a bug report for perl from demerphq@gmail.com, ----------------------------------------------------------------- $ ./perl -Ilib -wle'@Y::ISA=qw( Z ); @X::ISA=qw( Y ); print On one older perl (5.8.9) this throws a different set of warnings, $ perl -wle'@Y::ISA=qw( Z ); @X::ISA=qw( Y ); print Can't locate package Z for @Y::ISA. On blead we get the warnings, but at least the correct result. I don't think this should warn at all. Perl Info
|
From @demerphq0001-Improve-warnings-for-undefined-class-in-ISA.patchFrom f1e6479007985219e728573b9a294934f683b47b Mon Sep 17 00:00:00 2001
From: Yves Orton <demerphq@gmail.com>
Date: Sun, 17 Apr 2011 16:46:29 +0200
Subject: [PATCH] Improve warnings for undefined class in @ISA
And silence some silly examples.
---
gv.c | 19 +++++++++++-
pod/perldiag.pod | 12 ++++++++
t/lib/warnings/gv | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 109 insertions(+), 3 deletions(-)
diff --git a/gv.c b/gv.c
index d22a439..2b29531 100644
--- a/gv.c
+++ b/gv.c
@@ -486,8 +486,23 @@ Perl_gv_fetchmeth(pTHX_ HV *stash, const char *name, STRLEN len, I32 level)
cstash = gv_stashsv(linear_sv, 0);
if (!cstash) {
- Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), "Can't locate package %"SVf" for @%s::ISA",
- SVfARG(linear_sv), hvname);
+ if ( Perl_ckwarn(aTHX_ packWARN(WARN_SYNTAX)) &&
+ !( /* these are loaded from Perl_Gv_AMupdate() one way or another */
+ ( len && name[0] == '(' ) /* overload.pm related, in particular "()" */
+ || ( len==7 && strEQ( name, "DESTROY") )
+ || ( len==8 && strEQ( name, "AUTOLOAD") )
+ )
+ ) {
+ Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX),
+ "While trying to resolve method call %.*s->%.*s()"
+ " can not locate package \"%"SVf"\" yet it is mentioned in @%.*s::ISA"
+ " (perhaps you forgot to load \"%"SVf"\"?)",
+ packlen, hvname,
+ len, name,
+ SVfARG(linear_sv),
+ packlen, hvname,
+ SVfARG(linear_sv));
+ }
continue;
}
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 88c55a8..3b73f34 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -5487,6 +5487,18 @@ C<TEMPLATE> always matches the same amount of packed bytes that can be
determined from the template alone. This is not possible if it contains any
of the codes @, /, U, u, w or a *-length. Redesign the template.
+=item While trying to resolve method call %s->%s() can not locate package "%s" yet it is mentioned in @%s::ISA (perhaps you forgot to load "%s"?)
+
+(W) It is possible that the @ISA contains a misspelled or never loaded
+package name, which can result in perl choosing an unexpected parent
+classes method to resolve the method call. If this is deliberate you
+can do something like
+
+ @Missing::Package::ISA = ();
+
+to silence the warnings, otherwise you should correct the package name, or
+ensure that the package is loaded prior to the method call.
+
=item write() on closed filehandle %s
(W closed) The filehandle you're writing to got itself closed sometime
diff --git a/t/lib/warnings/gv b/t/lib/warnings/gv
index 42565f2..ea2f932 100644
--- a/t/lib/warnings/gv
+++ b/t/lib/warnings/gv
@@ -25,7 +25,6 @@ __END__
use warnings 'syntax' ;
@ISA = qw(Fred); joe()
EXPECT
-Can't locate package Fred for @main::ISA at - line 3.
Undefined subroutine &main::joe called at - line 3.
########
# gv.c
@@ -35,6 +34,86 @@ EXPECT
Undefined subroutine &main::joe called at - line 3.
########
# gv.c
+use warnings 'syntax' ;
+@ISA = qw(Fred); __PACKAGE__->joe()
+EXPECT
+While trying to resolve method call main->joe() can not locate package "Fred" yet it is mentioned in @main::ISA (perhaps you forgot to load "Fred"?) at - line 3.
+Can't locate object method "joe" via package "main" at - line 3.
+########
+# gv.c
+no warnings 'syntax' ;
+@ISA = qw(Fred); __PACKAGE__->joe()
+EXPECT
+Can't locate object method "joe" via package "main" at - line 3.
+########
+# gv.c
+use warnings 'syntax' ;
+{
+ package AA; # this is a deliberate error
+# package A; # should be this
+ sub foo {
+ print STDERR "I'm in A's foo\n";
+ }
+}
+{
+ package B;
+ sub foo {
+ print STDERR "I'm in B's foo\n";
+ }
+}
+@C::ISA = qw(A B);
+$a = bless [], 'C';
+$a->foo();
+__END__
+EXPECT
+While trying to resolve method call C->foo() can not locate package "A" yet it is mentioned in @C::ISA (perhaps you forgot to load "A"?) at - line 18.
+I'm in B's foo
+########
+# gv.c
+no warnings 'syntax' ;
+{
+ package AA; # this is a deliberate error
+# package A; # should be this
+ sub foo {
+ print STDERR "I'm in A's foo\n";
+ }
+}
+{
+ package B;
+ sub foo {
+ print STDERR "I'm in B's foo\n";
+ }
+}
+@C::ISA = qw(A B);
+$a = bless [], 'C';
+$a->foo();
+__END__
+EXPECT
+I'm in B's foo
+########
+# gv.c
+use warnings 'syntax' ;
+{
+# package AA; # this would be an error
+ package A; # the right thing
+ sub foo {
+ print STDERR "I'm in A's foo\n";
+ }
+}
+{
+ package B;
+ sub foo {
+ print STDERR "I'm in B's foo\n";
+ }
+}
+@C::ISA = qw(A B);
+$a = bless [], 'C';
+$a->foo();
+__END__
+EXPECT
+I'm in A's foo
+########
+# gv.c
sub Other::AUTOLOAD { 1 } sub Other::fred {}
@ISA = qw(Other) ;
use warnings 'deprecated' ;
--
1.7.0.4
|
From @jkeenanOn Sun Apr 17 08:24:41 2011, demerphq wrote:
What should be the desired behavior? Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @demerphqOn 26 September 2012 05:13, James E Keenan via RT
Thanks for reviving this, I think it either should not warn, or it As I recall I have a fix for this somewhere. Yves -- |
From @jkeenanOn Wed Sep 26 05:54:22 2012, demerphq wrote:
Have you had a chance to track down that fix? :-) |
From @demerphqOn 15 January 2013 03:55, James E Keenan via RT
Yeah, but some other patches conflicted and it got lost after a -- |
And silence some silly examples. From RT88754 Adapted to the current Perl by Max Maischein This patch deviates from the original author and makes the warning of category S (always) instead of the original warning category W (only with warnings). Please consider whether this should be changed. Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein This patch deviates from the original author and makes the warning of category S (always) instead of the original warning category W (only with warnings). Please consider whether this should be changed. Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein This patch deviates from the original author and makes the warning of category S (always) instead of the original warning category W (only with warnings). Please consider whether this should be changed. Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein Created from #11259
From RT88754 Adapted to the current Perl by Max Maischein Created from #11259
Migrated from rt.perl.org#88754 (status was 'open')
Searchable as RT88754$
The text was updated successfully, but these errors were encountered: