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

Perl produces silly and repetitive warnings for nonexistent packages in @ISA #11259

Closed
p5pRT opened this issue Apr 17, 2011 · 7 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented Apr 17, 2011

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

Searchable as RT88754$

@p5pRT
Copy link
Author

p5pRT commented Apr 17, 2011

From @demerphq

Created by @demerphq

This is a bug report for perl from demerphq@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.0.

-----------------------------------------------------------------
If @​ISA contains an unknown package name then we get lots of repetitve
and strange warnings​:

$ ./perl -Ilib -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
1

On one older perl (5.8.9) this throws a different set of warnings,
including one additional warning and returns FALSE​:

$ perl -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​Y​::ISA at -e line 1.

Can't locate package Z for @​Y​::ISA.
Can't locate package Z for @​Y​::ISA.
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

Flags:
    category=core
    severity=low

Site configuration information for perl 5.14.0:

Configured by yorton at Sun Apr 17 15:36:10 CEST 2011.

Summary of my perl5 (revision 5 version 14 subversion 0) configuration:
  Local Commit: f1e6479007985219e728573b9a294934f683b47b
  Ancestor: 40f026236b9959b7ad3260fedc6c66cd30bb7abc
  Platform:
    osname=linux, osvers=2.6.32-29-generic, archname=i686-linux
    uname='linux bagnost 2.6.32-29-generic #58-ubuntu smp fri feb 11
19:00:09 utc 2011 i686 gnulinux '
    config_args='-Doptimize=-ggdb3 -d -Dusedevel -Dcc=ccache gcc -Dld=gcc'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='ccache gcc', ccflags ='-fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
    optimize='-ggdb3',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.3', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/../lib/ /usr/lib/../lib/ /lib/
/usr/lib/ /usr/lib/i486-linux-gnu/ /lib /usr/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.11.1.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.11.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -ggdb3 -L/usr/local/lib
-fstack-protector'

Locally applied patches:
    RC0


@INC for perl 5.14.0:
    lib
    /usr/local/lib/perl5/site_perl/5.14.0/i686-linux
    /usr/local/lib/perl5/site_perl/5.14.0
    /usr/local/lib/perl5/5.14.0/i686-linux
    /usr/local/lib/perl5/5.14.0
    .


Environment for perl 5.14.0:
    HOME=/home/yorton
    LANG=en_US.utf8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/yorton/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/yorton/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 17, 2011

From @demerphq

0001-Improve-warnings-for-undefined-class-in-ISA.patch
From 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

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2012

From @jkeenan

On Sun Apr 17 08​:24​:41 2011, demerphq wrote​:

This is a bug report for perl from demerphq@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.0.

-----------------------------------------------------------------
If @​ISA contains an unknown package name then we get lots of repetitve
and strange warnings​:

$ ./perl -Ilib -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
1

On one older perl (5.8.9) this throws a different set of warnings,
including one additional warning and returns FALSE​:

$ perl -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​Y​::ISA at -e line 1.

Can't locate package Z for @​Y​::ISA.
Can't locate package Z for @​Y​::ISA.
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.

What should be the desired behavior?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2012

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

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2012

From @demerphq

On 26 September 2012 05​:13, James E Keenan via RT
<perlbug-followup@​perl.org> wrote​:

On Sun Apr 17 08​:24​:41 2011, demerphq wrote​:

This is a bug report for perl from demerphq@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.0.

-----------------------------------------------------------------
If @​ISA contains an unknown package name then we get lots of repetitve
and strange warnings​:

$ ./perl -Ilib -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
1

On one older perl (5.8.9) this throws a different set of warnings,
including one additional warning and returns FALSE​:

$ perl -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​Y​::ISA at -e line 1.

Can't locate package Z for @​Y​::ISA.
Can't locate package Z for @​Y​::ISA.
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.

What should be the desired behavior?

Thanks for reviving this, I think it either should not warn, or it
should point out the package is not loaded, but it should produce only
one warning, not three.

As I recall I have a fix for this somewhere.

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Jan 15, 2013

From @jkeenan

On Wed Sep 26 05​:54​:22 2012, demerphq wrote​:

On 26 September 2012 05​:13, James E Keenan via RT
<perlbug-followup@​perl.org> wrote​:

On Sun Apr 17 08​:24​:41 2011, demerphq wrote​:

This is a bug report for perl from demerphq@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.0.

-----------------------------------------------------------------
If @​ISA contains an unknown package name then we get lots of repetitve
and strange warnings​:

$ ./perl -Ilib -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
1

On one older perl (5.8.9) this throws a different set of warnings,
including one additional warning and returns FALSE​:

$ perl -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​Y​::ISA at -e line 1.

Can't locate package Z for @​Y​::ISA.
Can't locate package Z for @​Y​::ISA.
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.

What should be the desired behavior?

Thanks for reviving this, I think it either should not warn, or it
should point out the package is not loaded, but it should produce only
one warning, not three.

As I recall I have a fix for this somewhere.

Yves

Have you had a chance to track down that fix? :-)

@p5pRT
Copy link
Author

p5pRT commented Jan 15, 2013

From @demerphq

On 15 January 2013 03​:55, James E Keenan via RT
<perlbug-followup@​perl.org> wrote​:

On Wed Sep 26 05​:54​:22 2012, demerphq wrote​:

On 26 September 2012 05​:13, James E Keenan via RT
<perlbug-followup@​perl.org> wrote​:

On Sun Apr 17 08​:24​:41 2011, demerphq wrote​:

This is a bug report for perl from demerphq@​gmail.com,
generated with the help of perlbug 1.39 running under perl 5.14.0.

-----------------------------------------------------------------
If @​ISA contains an unknown package name then we get lots of repetitve
and strange warnings​:

$ ./perl -Ilib -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
Can't locate package Z for @​X​::ISA at -e line 1.
1

On one older perl (5.8.9) this throws a different set of warnings,
including one additional warning and returns FALSE​:

$ perl -wle'@​Y​::ISA=qw( Z ); @​X​::ISA=qw( Y ); print
UNIVERSAL​::isa(bless([],"X"),"Z")'
Can't locate package Z for @​Y​::ISA at -e line 1.

Can't locate package Z for @​Y​::ISA.
Can't locate package Z for @​Y​::ISA.
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.

What should be the desired behavior?

Thanks for reviving this, I think it either should not warn, or it
should point out the package is not loaded, but it should produce only
one warning, not three.

As I recall I have a fix for this somewhere.

Yves

Have you had a chance to track down that fix? :-)

Yeah, but some other patches conflicted and it got lost after a
production release. Ill try to roll a new one.

--
perl -Mre=debug -e "/just|another|perl|hacker/"

Corion pushed a commit that referenced this issue Oct 25, 2019
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
Corion pushed a commit that referenced this issue Oct 25, 2019
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
Corion pushed a commit that referenced this issue Oct 25, 2019
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
Corion pushed a commit that referenced this issue Oct 25, 2019
From RT88754

Adapted to the current Perl by Max Maischein

Created from #11259
Corion pushed a commit that referenced this issue Oct 25, 2019
From RT88754

Adapted to the current Perl by Max Maischein

Created from #11259
Corion pushed a commit that referenced this issue Oct 25, 2019
From RT88754

Adapted to the current Perl by Max Maischein

Created from #11259
Corion pushed a commit that referenced this issue Nov 3, 2019
From RT88754

Adapted to the current Perl by Max Maischein

Created from #11259
@Corion Corion closed this as completed Nov 22, 2019
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

2 participants