[perl #74740] Deparse -(f()) correctly
authorFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 21:16:48 +0000 (13:16 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 8 Dec 2011 21:51:20 +0000 (13:51 -0800)
-(f()) was being deparsed as -f(), which is a filetest operator.

Extra parens are needed for negation if the child op deparses with a
single letter at the beginning.

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t

index 821cce1..10ab498 100644 (file)
@@ -1629,7 +1629,13 @@ sub pfixop {
     my($op, $cx, $name, $prec, $flags) = (@_, 0);
     my $kid = $op->first;
     $kid = $self->deparse($kid, $prec);
-    return $self->maybe_parens(($flags & POSTFIX) ? "$kid$name" : "$name$kid",
+    return $self->maybe_parens(($flags & POSTFIX)
+                                ? "$kid$name"
+                                  # avoid confusion with filetests
+                                : $name eq '-'
+                                  && $kid =~ /^[a-zA-Z](?!\w)/
+                                       ? "$name($kid)"
+                                       : "$name$kid",
                               $cx, $prec);
 }
 
index 8f2a4b8..d71eeaa 100644 (file)
@@ -878,3 +878,6 @@ CORE::do({});
 # [perl #63558] open local(*FH)
 open local *FH;
 pipe local *FH, local *FH;
+####
+# [perl #74740] -(f()) vs -f()
+$_ = -(f());