develooper Front page | perl.perl5.porters | Postings from December 2015

Re: [perl #127026] B::Deparse fails to correctly deparse hash-derefswith conditional logic within

Thread Previous | Thread Next
From:
Zefram
Date:
December 25, 2015 04:06
Subject:
Re: [perl #127026] B::Deparse fails to correctly deparse hash-derefswith conditional logic within
Message ID:
20151225040632.GG7818@fysh.org
yves orton wrote:
>$ perl -MO=Deparse -e'$x=sub{ scalar %{ delete $_{x} || {} } }; print $x->();'
>$x = sub {
>    scalar %{{} unless delete $_{'x'};};

This deparse isn't horribly incorrect.  It's essentially correct: an
oddity of the sigil+braces syntax is that the braced group is a code
block, within which statement syntax prevails, not expression syntax.

The strange thing is why the output isn't accepted by the parser.
The error message, "unmatched right curly bracket", looks incorrect,
and several minor variations on the input lead to it being accepted.
What's actually going on is that "%{{}" is interpreted as a reference to
the hash whose name is just an open brace character.  This is rather
insane; "%{" is never interpreted that way, and we don't have any
meaningful variables with such names.  We might want to change that
behaviour, but it is rather long-standing.

B::Deparse could work around this by adding a semicolon after the first
open brace.  To be nice we'd really want it to only do that if the code
to go in the braced block starts with the problematic "{}".

-zefram

Thread Previous | 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