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
\$ prototype does not make a unary function #10457
Comments
From @cpansprout$ perl -le' sub foo($) { print "foo" }; foo $_, exit' So it looks as though the parser does not consider it unary, but op.c Flags: Site configuration information for perl 5.13.1: Configured by sprout at Tue Jun 15 06:25:06 PDT 2010. Summary of my perl5 (revision 5 version 13 subversion 1 patch Locally applied patches: @INC for perl 5.13.1: Environment for perl 5.13.1: |
From @cpansproutOn Jun 20, 2010, at 2:32 PM, Father Chrysostomos wrote:
This problem is worse than I thought. It applies to these prototypes as well: * This means that the following functions, among others, cannot be overridden by subs that parse the same way: fileno (*) The attached patch fixes these. I hope no-one minds the space-out ‘if’ condition. I just find it *much* easier to read that way. |
From @cpansproutInline Patch--- blead/toke.c 2010-07-17 18:51:14.000000000 -0700
+++ blead-ref-proto/toke.c 2010-07-19 22:03:26.000000000 -0700
@@ -6493,10 +6493,27 @@ Perl_yylex(pTHX)
const char *proto = SvPV_const(MUTABLE_SV(cv), protolen);
if (!protolen)
TERM(FUNC0SUB);
- if ((*proto == '$' || *proto == '_') && proto[1] == '\0')
- OPERATOR(UNIOPSUB);
while (*proto == ';')
proto++;
+ if (
+ (
+ (
+ *proto == '$' || *proto == '_'
+ || *proto == '*'
+ )
+ && proto[1] == '\0'
+ )
+ || (
+ *proto == '\\' && proto[1] && proto[2] == '\0'
+ )
+ )
+ OPERATOR(UNIOPSUB);
+ if (*proto == '\\' && proto[1] == '[') {
+ const char *p = proto + 2;
+ while(*p && *p != ']')
+ ++p;
+ if(*p == ']' && !p[1]) OPERATOR(UNIOPSUB);
+ }
if (*proto == '&' && *s == '{') {
if (PL_curstash)
sv_setpvs(PL_subname, "__ANON__");
--- blead/t/comp/proto.t 2009-11-19 08:51:40.000000000 -0800
+++ blead-ref-proto/t/comp/proto.t 2010-07-19 21:32:28.000000000 -0700
@@ -18,7 +18,7 @@ BEGIN {
# strict
use strict;
-print "1..153\n";
+print "1..160\n";
my $i = 1;
@@ -651,3 +651,28 @@ print "ok ", $i++, "\n";
eval 'sub bug (\[%@]) { } my $array = [0 .. 1]; bug %$array;';
print "not " unless $@ =~ /Not a HASH reference/;
print "ok ", $i++, "\n";
+
+# [perl #75904]
+# Test that the following prototypes make subs parse as unary functions:
+# * \sigil \[...] ;$ ;* ;\sigil ;\[...]
+print "not "
+ unless eval 'sub uniproto1 (*) {} uniproto1 $_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto2 (\$) {} uniproto2 $_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto3 (\[$%]) {} uniproto3 %_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto4 (;$) {} uniproto4 $_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto5 (;*) {} uniproto5 $_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto6 (;\@) {} uniproto6 @_, 1' or warn $@;
+print "ok ", $i++, "\n";
+print "not "
+ unless eval 'sub uniproto7 (;\[$%@]) {} uniproto7 @_, 1' or warn $@;
+print "ok ", $i++, "\n"; |
From @rgarciaOn 25 July 2010 21:43, Father Chrysostomos <sprout@cpan.org> wrote:
The patch looks good and the result is more consistent parsing. Also, Opinions ? Should I apply ? |
The RT System itself - Status changed from 'new' to 'open' |
From @raflRafael Garcia-Suarez <rgs@consttype.org> writes:
It also looks good to me, passes all tests, and does fix an actual |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#75904 (status was 'resolved')
Searchable as RT75904$
The text was updated successfully, but these errors were encountered: