In the case of a sub definition with a prototype, the prototype
is not attached to the sub until after the body is completely
defined. This means that any sub which calls itself will
not honor its prototype unless the prototype was declared prior to
the sub's definition. Whether or not this behavior is desirable is
debatable, but its far too late to do anything about it other than
document it and test to make sure it doesn't change.
in C<@foo>. And the C<split> gets called in scalar context so it
starts scribbling on your C<@_> parameter list. Ouch!
+If a sub has both a PROTO and a BLOCK, the prototype is not applied
+until after the BLOCK is completely defined. This means that a recursive
+function with a prototype has to be predeclared for the prototype to take
+effect, like so:
+
+ sub foo($$);
+ sub foo($$) {
+ foo 1, 2;
+ }
+
This is all very powerful, of course, and should be used only in moderation
to make the world a better place.
# strict
use strict;
-print "1..199\n";
+print "1..201\n";
my $i = 1;
print "not " unless eval 'star4 STDERR; 1';
print "ok ", $i++, " star4 STDERR\n";
+# [perl #2726]
+# Test that prototype binding is late
+print "not " unless eval 'sub l564($){ l564(); } 1';
+print "ok ", $i++, " prototype checking not done within initial definition\n";
+print "not " if eval 'sub l566($); sub l566($){ l566(); } 1';
+print "ok ", $i++, " prototype checking done if sub pre-declared\n";
+
# test scalarref prototype
sub sreftest (\$$) {
print "not " unless ref $_[0];