From 7f5da0ae51220d02a7f9a1fe93e2c6180f917639 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 17 Mar 2021 09:39:29 -0700 Subject: [PATCH] Fix definition of list within list for -bbx flag --- lib/Perl/Tidy/Formatter.pm | 33 +++++++++++++++++++++------------ local-docs/BugLog.pod | 15 ++++++++++++--- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index df8f5d80..021b6f4e 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -354,6 +354,7 @@ BEGIN { _rlec_count_by_seqno_ => $i++, _ris_broken_container_ => $i++, _ris_permanently_broken_container_ => $i++, + _rhas_list_ => $i++, _rhas_broken_list_ => $i++, _rhas_broken_list_with_lec_ => $i++, _rwant_reduced_ci_ => $i++, @@ -700,6 +701,7 @@ sub new { $self->[_rlec_count_by_seqno_] = {}; $self->[_ris_broken_container_] = {}; $self->[_ris_permanently_broken_container_] = {}; + $self->[_rhas_list_] = {}; $self->[_rhas_broken_list_] = {}; $self->[_rhas_broken_list_with_lec_] = {}; $self->[_rwant_reduced_ci_] = {}; @@ -4821,6 +4823,7 @@ sub respace_tokens { my $rlec_count_by_seqno = {}; my $ris_broken_container = {}; my $ris_permanently_broken_container = {}; + my $rhas_list = {}; my $rhas_broken_list = {}; my $rhas_broken_list_with_lec = {}; my $rparent_of_seqno = {}; @@ -5809,19 +5812,21 @@ sub respace_tokens { # We will define a list to be a container with one or more commas and # no semicolons. my $is_list = ( $comma_count || $fat_comma_count ) && !$semicolon_count; - if ($is_list) { $ris_list_by_seqno->{$seqno} = $seqno } - - if ($line_diff) { + if ($is_list) { + $ris_list_by_seqno->{$seqno} = $seqno; my $seqno_parent = $rparent_of_seqno->{$seqno}; if ( defined($seqno_parent) && $seqno_parent ne SEQ_ROOT ) { - $rhas_broken_list->{$seqno_parent} = 1 if ($is_list); + $rhas_list->{$seqno_parent} = 1; + if ($line_diff) { + $rhas_broken_list->{$seqno_parent} = 1; - # We need to mark broken lists with non-terminal line-ending - # commas for the -bbx=2 parameter. This insures that the list - # will stay broken. Otherwise the flag -bbx=2 can be unstable. - # This fixes case b789 and b938. - $rhas_broken_list_with_lec->{$seqno_parent} = 1 - if ( $rlec_count_by_seqno->{$seqno} ); + # We need to mark broken lists with non-terminal + # line-ending commas for the -bbx=2 parameter. This insures + # that the list will stay broken. Otherwise the flag + # -bbx=2 can be unstable. This fixes case b789 and b938. + $rhas_broken_list_with_lec->{$seqno_parent} = 1 + if ( $rlec_count_by_seqno->{$seqno} ); + } } } } @@ -5839,6 +5844,7 @@ sub respace_tokens { $self->[_rtype_count_by_seqno_] = $rtype_count_by_seqno; $self->[_rlec_count_by_seqno_] = $rlec_count_by_seqno; $self->[_ris_broken_container_] = $ris_broken_container; + $self->[_rhas_list_] = $rhas_list; $self->[_rhas_broken_list_] = $rhas_broken_list; $self->[_rhas_broken_list_with_lec_] = $rhas_broken_list_with_lec; $self->[_rparent_of_seqno_] = $rparent_of_seqno; @@ -7952,6 +7958,7 @@ sub break_before_list_opening_containers { my $ris_broken_container = $self->[_ris_broken_container_]; my $ris_permanently_broken_container = $self->[_ris_permanently_broken_container_]; + my $rhas_list = $self->[_rhas_list_]; my $rhas_broken_list = $self->[_rhas_broken_list_]; my $rhas_broken_list_with_lec = $self->[_rhas_broken_list_with_lec_]; my $radjusted_levels = $self->[_radjusted_levels_]; @@ -7977,11 +7984,13 @@ sub break_before_list_opening_containers { my $KK = $K_opening_container->{$seqno}; my $is_list = $self->is_list_by_seqno($seqno); - my $has_list = $rhas_broken_list->{$seqno}; + my $has_list = $rhas_list->{$seqno}; + my $has_broken_list = $rhas_broken_list->{$seqno}; my $has_list_with_lec = $rhas_broken_list_with_lec->{$seqno}; # This must be a list (this will exclude all code blocks) - # or contain a list + # or contain a list. + # Note: switched from testing has_broken_list to has_list to fix b1024. next unless ( $is_list || $has_list ); # Only for types of container tokens with a non-default break option diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index f09a1faf..4720c406 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,13 +2,22 @@ =over 4 +=item B + +Testing produced a blinking state involving a -bbx=2 flag with an unusual +combination of other parameters. The problem was traced to the definition of a +list containg another list being too restrictive. This update fixes case +1024. + +17 Mar 2021. + =item B Testing produced an unstable situation involving the -xci flag and tokens which exceed the maximum line length. This fix identifies this situation and locally deactivates the -xci flag. This fixes case b1031. -16 Mar 2021. +16 Mar 2021, 7a6be43. =item B @@ -20,7 +29,7 @@ continuation indentation within the braces. The problem was fixed. This fixes cases b1022 b1025 b1026 b1027 b1028 b1029 b1030 -16 Mar 2021. +16 Mar 2021, 6371be2. =item B @@ -31,7 +40,7 @@ testing. This update fixes these issues. The following cases are fixed: b1019 b1020 b1021 b1023 -13 Mar 2021. +13 Mar 2021, 71adc77. =item B -- 2.39.5