From db9cb436a7d27b1d97b5b1f8aadc78fc9b3c04bd Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 26 Jul 2024 20:58:49 -0700 Subject: [PATCH] revise -duv coding for signature in signature --- lib/Perl/Tidy/Formatter.pm | 58 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 6d51af7a..3a525f3e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -9099,29 +9099,47 @@ sub scan_variable_usage { my $check_sub_signature = sub { my ($KK) = @_; - # check for signature list - my ( $seqno_brace, $K_end_iterator ) = - $self->block_seqno_of_paren_keyword($KK); + # looking for a sub signature + # sub xxx (...) { + # ------- + # | | | | + # $KK $Kn | | + # $K_opening_brace + + # Note: this version cannot handle signatures within signatures. + # Inner signatures are currently ignored. For example, only the + # outermost $a below will be checked in this line: + + # sub xyz ($a = sub ($a) { $a."z" }) { $a->("a")."y" } + + # What happens is that variable $K_end_my is set by the first + # signature, and the second signature is within it and so does + # not get activated. A stack scheme would be necessary to handle + # this, but does not seem necessary because this probably only + # occurs in test code, and the only downside is that we limit + # some checking. - # found signature? - if ($seqno_brace) { - - # Treat signature variables like my variables - my $K_opening_brace = - $self->[_K_opening_container_]->{$seqno_brace}; - - if ( $K_opening_brace && $K_opening_brace > $K_end_my ) { - $K_end_my = $K_opening_brace; - $my_keyword = 'sub signature'; - } - - my $K_opening_paren = $self->K_next_code($KK); - $in_signature_seqno = $rLL->[$K_opening_paren]->[_TYPE_SEQUENCE_]; - - # Create special block on the stack..see note above for - # $is_if_unless + my $Kn = $self->K_next_code($KK); + return unless ( $rLL->[$Kn]->[_TOKEN_] eq '(' ); + my $seqno_paren = $rLL->[$Kn]->[_TYPE_SEQUENCE_]; + return unless ($seqno_paren); + my $K_closing_paren = $self->[_K_closing_container_]->{$seqno_paren}; + my $K_opening_brace = $self->K_next_code($K_closing_paren); + return unless ($K_opening_brace); + my $seqno_brace = $rLL->[$K_opening_brace]->[_TYPE_SEQUENCE_]; + my $token_brace = $rLL->[$K_opening_brace]->[_TOKEN_]; + return unless ( $seqno_brace && $token_brace eq '{' ); + + # Treat signature variables like my variables + # Create special block on the stack..see note above for + # $is_if_unless + if ( $K_opening_brace > $K_end_my ) { + $K_end_my = $K_opening_brace; + $my_keyword = 'sub signature'; + $in_signature_seqno = $seqno_paren; $push_block_stack->($seqno_brace); } + return; }; #-------------------- -- 2.39.5