From c9a237f5c82cb56c14d0489e68dc8fc7c7db8855 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 7 Jan 2022 06:49:05 -0800 Subject: [PATCH] fix instabilities b1274 b1275 involving combo -bbx=2 -lp or -vmll --- dev-bin/run_convergence_tests.pl.data | 72 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 62 +++++++++++++++++++---- 2 files changed, 125 insertions(+), 9 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 74556436..54868763 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -8605,6 +8605,78 @@ use overload --keyword-paren-inner-tightness=2 --maximum-line-length=56 +==> b1274.in <== +# S1 + $$d{"month_abb"} = [ + [ + "Jan", "Feb", "Mar", "Apr", + "Maj", "Jun", "Jul", "Aug", + "Sep", "Okt", "Nov", "Dec" + ] + ]; +# S2 + $$d{"month_abb"} = + [ + [ + "Jan", "Feb", "Mar", "Apr", "Maj", "Jun", + "Jul", "Aug", "Sep", "Okt", "Nov", "Dec" + ] + ]; + +# S3 + $$d{"month_abb"} = [ + [ + "Jan", "Feb", "Mar", "Apr", "Maj", "Jun", + "Jul", "Aug", "Sep", "Okt", "Nov", "Dec" + ] + ]; + + + +==> b1274.par <== +--break-before-square-bracket=2 +--continuation-indentation=0 +--extended-line-up-parentheses +--ignore-old-breakpoints +--indent-columns=7 +--maximum-line-length=56 + +==> b1275.in <== + $$d{"month_abb"} = [ + [ + "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paz.", "lis.", "gru." + ], [ + "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paŸ.", "lis.", "gru." + ] + ]; + + $$d{"month_abb"} = [ + [ "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paz.", "lis.", "gru." ], + [ "sty.", "lut.", "mar.", "kwi.", "maj", "cze.", "lip.", "sie.", "wrz.", "paŸ.", "lis.", "gru." ] + ]; + +==> b1275.par <== +--break-before-square-bracket=2 +--continuation-indentation=3 +--extended-continuation-indentation +--maximum-line-length=100 +--opening-square-bracket-right +--nostack-closing-block-brace +--nostack-closing-hash-brace +--nostack-closing-paren +--nostack-closing-square-bracket +--nostack-opening-hash-brace +--nostack-opening-paren +--nostack-opening-square-bracket +--nostatic-block-comments +--notight-secret-operators +--notrim-pod +--use-unicode-gcstring +--novalign-side-comments +--variable-maximum-line-length +--vertical-tightness-closing=0 +--vertical-tightness=0 + ==> b1277.in <== # S1 match_on_type @_ => Null => sub { [] }, diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 8d7a6145..f8bbb907 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -9825,6 +9825,59 @@ sub break_before_list_opening_containers { my $ci = $rLL->[$KK]->[_CI_LEVEL_]; + #-------------------------------------------- + # New coding for option 2 (break if complex). + #-------------------------------------------- + # This new coding uses clues which are invariant under formatting to + # decide if a list is complex. For now it is only applied when -lp + # and -vmll are used, but eventually it may become the standard method. + # Fixes b1274, b1275, and others, including b1099. + if ( $break_option == 2 ) { + + if ( $rOpts_line_up_parentheses + || $rOpts_variable_maximum_line_length ) + { + + # Start with the basic definition of a complex list... + my $is_complex = $is_list && $has_list; + + # and it is also complex if the parent is a list + if ( !$is_complex ) { + my $parent = $rparent_of_seqno->{$seqno}; + if ( $self->is_list_by_seqno($parent) ) { + $is_complex = 1; + } + } + + # finally, we will call it complex if there are inner opening + # and closing container tokens within the outer container + # tokens. + if ( !$is_complex ) { + my $Kp = $self->K_next_nonblank($KK); + my $type_p = defined($Kp) ? $rLL->[$Kp]->[_TYPE_] : 'b'; + if ( $is_opening_type{$type_p} ) { + + my $Kc = $K_closing_container->{$seqno}; + my $Km = $self->K_previous_nonblank($Kc); + my $type_m = defined($Km) ? $rLL->[$Km]->[_TYPE_] : 'b'; + + # ignore any optional ending comma + if ( $type_m eq ',' ) { + $Km = $self->K_previous_nonblank($Km); + $type_m = + defined($Km) ? $rLL->[$Km]->[_TYPE_] : 'b'; + } + + $is_complex ||= $is_closing_type{$type_m}; + } + } + + # Convert to option 3 (always break) if complex + next unless ($is_complex); + $break_option = 3; + } + } + # Fix for b1231: the has_list_with_lec does not cover all cases. # A broken container containing a list and with line-ending commas # will stay broken, so can be treated as if it had a list with lec. @@ -9874,15 +9927,6 @@ sub break_before_list_opening_containers { } } - # Patch to fix b1099 for -lp - # ok in -lp mode if this is a list which contains a list - if ( !$ok_to_break && $rOpts_line_up_parentheses ) { - if ( $is_list && $has_list ) { - $ok_to_break = 1; - DEBUG_BBX && do { $Msg = "is list or has list" }; - } - } - if ( !$ok_to_break ) { DEBUG_BBX && print STDOUT "Not breaking at seqno=$seqno: $Msg\n"; -- 2.39.5