develooper Front page | perl.perl5.porters | Postings from April 2003

[PATCH] buglet: sub a(;&) { } doesn't work

Thread Next
From:
Enache Adrian
Date:
April 18, 2003 15:48
Subject:
[PATCH] buglet: sub a(;&) { } doesn't work
Message ID:
20030418224107.GA2751@ratsnest.hole
$ perl -e 'sub a(;&) { } a { }'
Type of arg 1 to main::a must be block or sub {} (not single ref constructor) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

No, this is not a "feature": if it was, perl would drop the prototype
in the first place, not go on and parse { } as a hash ref constructor.

diff -rup /arc/bleadperl/t/comp/parser.t bleadperl/t/comp/parser.t
--- /arc/bleadperl/t/comp/parser.t	2003-03-14 23:39:54.000000000 +0200
+++ bleadperl/t/comp/parser.t	2003-04-19 01:11:32.000000000 +0300
@@ -9,7 +9,7 @@ BEGIN {
 }
 
 require "./test.pl";
-plan( tests => 21 );
+plan( tests => 22 );
 
 eval '%@x=0;';
 like( $@, qr/^Can't modify hash dereference in repeat \(x\)/, '%@x=0' );
@@ -89,6 +89,9 @@ ${a}{ ${a}[ @{b}{
 ${a}{
 }
 
+eval q{ sub a(;; &) { } a { } };
+is($@, '', "';&' sub prototype confuses the lexer");
+
 # Bug #21575
 # ensure that the second print statement works, by playing a bit
 # with the test output.
diff -rup /arc/bleadperl/toke.c bleadperl/toke.c
--- /arc/bleadperl/toke.c	2003-04-17 00:25:37.000000000 +0300
+++ bleadperl/toke.c	2003-04-19 01:10:41.000000000 +0300
@@ -4076,6 +4076,8 @@ Perl_yylex(pTHX)
 			    TERM(FUNC0SUB);
 			if (strEQ(proto, "$"))
 			    OPERATOR(UNIOPSUB);
+			while (*proto == ';')
+			    proto++;
 			if (*proto == '&' && *s == '{') {
 			    sv_setpv(PL_subname, PL_curstash ? 
 					"__ANON__" : "__ANON__::__ANON__");

Regards
Adi

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About