This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
deparse pragmas before subs
authorDavid Mitchell <davem@iabyn.com>
Wed, 20 Jul 2016 16:31:00 +0000 (17:31 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Aug 2016 19:54:40 +0000 (20:54 +0100)
commitbc304ab29c846b89ecada79bc60b7a841981bab2
tree6c8d62530332f13bca949b7345cd8496ffe98733
parent4fa06845e75d453a3101cff32e24c5b743f9819e
deparse pragmas before subs

Currently something like this:

    use strict;
    sub f {
        print;
    }
    print;

deparses as:

    sub f {
        use strict;
        print $_;
    }
    use strict;
    print $_;

(Note where the 'strict's appear). Although ugly, this is semantically
correct for most pragmas. However, it breaks down for "use feature
'signatures'", since that needs to appear before the sub if the
deparsing of the sub's header is altered to reflect signature syntax or
not, based on whether the pragma is in scope.

This commit changes the deparsing of each nextstate op so that it outputs
any pragmas which reflect changes since the last nextstate's hints etc,
*before* deparsing any subs whose COP is less than that of the new
nextstate. After this commit, the code above deparses as:

    use strict;
    sub f {
        print $_;
    }
    print $_;

It also allows some hacky code to be removed from Deparse.pm that
ensured that "no warnings experimental::lexical_subs" appeared before
each lexical sub was deparsed.

[ This fix is not comprehensive; a fuller fix comes in a few commits time ]
lib/B/Deparse-core.t
lib/B/Deparse.pm
lib/B/Deparse.t