diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-12-08 12:49:33 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-12-08 13:50:49 -0800 |
commit | 4d8ac5c735b4377aecb531044f04c9917054ba71 (patch) | |
tree | 852c25c18d9c4569fd8f70cc3e0345359b245171 /dist | |
parent | 2462c3ccada0e87002e4f7dc42bfcdfe36fe678a (diff) | |
download | perl-4d8ac5c735b4377aecb531044f04c9917054ba71.tar.gz |
Deparse (eof)+1 correctly
If the parentheses are omitted, it means eof(1).
To fix this, we surround the keyword with parentheses (if necessary
according to precedence) if it is an unop, because a final () has a
special meaning for some unops.
For listops, we use surrounding parentheses only if the llafr does
not apply. Otherwise we use a final ().
Diffstat (limited to 'dist')
-rw-r--r-- | dist/B-Deparse/Deparse.pm | 16 | ||||
-rw-r--r-- | dist/B-Deparse/t/deparse.t | 6 |
2 files changed, 19 insertions, 3 deletions
diff --git a/dist/B-Deparse/Deparse.pm b/dist/B-Deparse/Deparse.pm index 24b560673f..792cfd516e 100644 --- a/dist/B-Deparse/Deparse.pm +++ b/dist/B-Deparse/Deparse.pm @@ -1692,8 +1692,10 @@ sub unop { } return $self->maybe_parens_unop($name, $kid, $cx); } else { - return $self->keyword($name) - . ($op->flags & OPf_SPECIAL ? "()" : ""); + return $self->maybe_parens( + $self->keyword($name) . ($op->flags & OPf_SPECIAL ? "()" : ""), + $cx, 16, + ); } } @@ -2364,7 +2366,15 @@ sub listop { my(@exprs); my $parens = ($cx >= 5) || $self->{'parens'}; $kid ||= $op->first->sibling; - return $self->keyword($name) if null $kid; + # If there are no arguments, add final parentheses (or parenthesize the + # whole thing if the llafr does not apply) to account for cases like + # (return)+1 or setpgrp()+1. When the llafr does not apply, we use a + # precedence of 6 (< comma), as "return, 1" does not need parentheses. + if (null $kid) { + return $nollafr + ? $self->maybe_parens($self->keyword($name), $cx, 7) + : $self->keyword($name) . '()' x (7 < $cx); + } my $first; $name = "socketpair" if $name eq "sockpair"; my $fullname = $self->keyword($name); diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t index 52a20d9ddd..4905d54a30 100644 --- a/dist/B-Deparse/t/deparse.t +++ b/dist/B-Deparse/t/deparse.t @@ -869,5 +869,11 @@ CORE::do({}); () = (-w $_) + 3; () = (-x $_) + 3; #### +# Precedence conundrums with argument-less function calls +() = (eof) + 1; +() = (return) + 1; +() = (return, 1); +() = setpgrp() + 1; +#### # [perl #63558] open local(*FH) open local *FH; |