Skip to content

Commit

Permalink
Deparse.pm: handle signatures under 'use v5.36'
Browse files Browse the repository at this point in the history
Deparse.pm was checking for the equivalent of

    use feature 'signatures';

being in scope when deciding whether to deparse a sub using signature
syntax. However, since 5.36.0, signatures can also be be enabled via

    use v5.36;

but Deparse wasn't checking for this (the latter is stored in hints
rather than in features).

I haven't added a test as 'use v.5.36' itself currently doesn't deparse
cleanly; however, this commit means that

    #use feature 'signatures';
    use v5.36;

    sub f($x,$y) {
        return $x + $y;
    }

used to deparse as:

    sub f {
        do {
            die sprintf("Too many arguments for subroutine at %s line %d.\n", (caller)[1, 2]) unless @_ <= 2;
        ...
    }

but now correctly deparses as:

    sub f ($x, $y) {
        ...
    }

Uncommenting the 'use feature' line instead worked both before and now.

It was showing up as this failing:

    cd t; ./TEST -deparse ../lib/builtin.t
  • Loading branch information
iabyn committed May 26, 2023
1 parent b99e539 commit 90fd99b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/B/Deparse.pm
Expand Up @@ -1316,7 +1316,7 @@ Carp::confess("NULL in deparse_sub") if !defined($cv) || $cv->isa("B::NULL");
Carp::confess("SPECIAL in deparse_sub") if $cv->isa("B::SPECIAL");
local $self->{'curcop'} = $self->{'curcop'};

my $has_sig = $self->{hinthash}{feature_signatures};
my $has_sig = $self->feature_enabled('signatures');
if ($cv->FLAGS & SVf_POK) {
my $myproto = $cv->PV;
if ($has_sig) {
Expand Down Expand Up @@ -2334,6 +2334,7 @@ my %feature_keywords = (
catch => 'try',
finally => 'try',
defer => 'defer',
signatures => 'signatures',
);

# keywords that are strong and also have a prototype
Expand Down

0 comments on commit 90fd99b

Please sign in to comment.