Bug#582525: called to early to check prototype but no warning, docs vague

Ian Jackson ijackson at chiark.greenend.org.uk
Fri May 21 15:35:24 UTC 2010


Package: perl
Version: 5.10.0-19lenny2

Summary: it is possible for a function to be called too early to check
 its prototype but for this not to generate the "called too early to
 check prototype" warning.  Also the documentation is less than ideal.


In the example t.pl below, the function spong is called by zoom, which
is lexically before the definition of spong.  The output shows that
spong's prototype is not being used for the call from zoom.  However,
this does not generate any warning.

Contrast this to u.pl which calls spong directly from the main
program, lexically before spong's definition.  This generates the
warning as I think it should.

It would be nice if t.pl generated a warning.  Of course it would be
even nicer if it honoured the prototype but I guess that won't happen
because it could easily break existing scripts which currently work by
accident (not to mention that it might complicate the implementation).


It would also be nice if the documentation was more forthcoming.  As
far as I can see in all the Perl manpages, the only thing which
mentions visibility of prototype declarations is this statement in
perlsub:
  The function declaration must be visible at compile time.

It doesn't explain what that means and the actual behaviour is less
helpful than it could be.  Given that failing to honour the prototype
can cause wrong behaviour (well, behaviour not intended by the
programmer) I think a stronger warning, and preferably more detail, in
the manpage would be helpful.


Thanks,
Ian.


chiark:~> cat t.pl
use warnings;
use strict;

use Data::Dumper;

sub zoom () { my @zorkmid = qw(1 2 3);  spong('zoom', @zorkmid); }
sub spong ($\@) { print Dumper(\@_); }

zoom();

my @poe = qw(a b c);   spong('main', @poe);
chiark:~> perl t.pl
$VAR1 = [
          'zoom',
          '1',
          '2',
          '3'
        ];
$VAR1 = [
          'main',
          [
            'a',
            'b',
            'c'
          ]
        ];
chiark:~> cat u.pl
use warnings;
use strict;

use Data::Dumper;

my @zorkmid = qw(1 2 3);  spong('zoom', @zorkmid);

sub spong ($\@) { print Dumper(\@_); }

my @poe = qw(a b c);   spong('main', @poe);
chiark:~> perl u.pl
main::spong() called too early to check prototype at u.pl line 6.
$VAR1 = [
          'zoom',
          '1',
          '2',
          '3'
        ];
$VAR1 = [
          'main',
          [
            'a',
            'b',
            'c'
          ]
        ];
chiark:~>






More information about the Perl-maintainers mailing list