(W syntax) An illegal character was found in a prototype declaration. Legal
characters in prototypes are $, @, %, *, ;, [, ], &, and \.
+=item Illegal declaration of anonymous subroutine
+
+(F) When using the C<sub> keyword to construct an anonymous subroutine,
+you must always specify a block of code. See L<perlsub>.
+
=item Illegal division by zero
(F) You tried to divide a number by 0. Either something was wrong in
#!./perl
+# Note : we're not using t/test.pl here, because we would need
+# fresh_perl_is, and fresh_perl_is uses a closure -- a special
+# case of what this program tests for.
+
chdir 't' if -d 't';
@INC = '../lib';
$Is_VMS = $^O eq 'VMS';
undef $/;
@prgs = split "\n########\n", <DATA>;
-print "1..", scalar @prgs, "\n";
+print "1..", 6 + scalar @prgs, "\n";
$tmpfile = "asubtmp000";
1 while -f ++$tmpfile;
print "ok ", ++$i, "\n";
}
+sub test_invalid_decl {
+ my ($code,$todo) = @_;
+ $todo //= '';
+ eval $code;
+ if ($@ =~ /^Illegal declaration of anonymous subroutine at/) {
+ print "ok ", ++$i, " - '$code' is illegal$todo\n";
+ } else {
+ print "not ok ", ++$i, " - '$code' is illegal$todo\n# GOT: $@";
+ }
+}
+
+test_invalid_decl('sub;');
+test_invalid_decl('sub ($) ;');
+test_invalid_decl('{ $x = sub }');
+test_invalid_decl('sub ($) && 1');
+test_invalid_decl('sub ($) : lvalue;',' # TODO');
+
+eval "sub #foo\n{print 1}";
+if ($@ eq '') {
+ print "ok ", ++$i, "\n";
+} else {
+ print "not ok ", ++$i, "\n# GOT: $@";
+}
+
__END__
sub X {
my $n = "ok 1\n";
if (*s == ':' && s[1] != ':')
PL_expect = attrful;
+ else if (!have_name && *s != '{' && key == KEY_sub)
+ Perl_croak(aTHX_ "Illegal declaration of anonymous subroutine");
if (have_proto) {
PL_nextval[PL_nexttoke].opval =