From c74c2e3ebc5a15941f53ae3f69121966d2559884 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 24 Apr 2022 07:01:46 -0700 Subject: [PATCH] fix potential conflict of -wn -lp -pvt=2, b1338 --- dev-bin/run_convergence_tests.pl.data | 19 +++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 81bb70cc..fe7aeeec 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -9783,6 +9783,25 @@ params => --maximum-line-length=19 --variable-maximum-line-length +==> b1338.in <== +# S1: + ( + sockaddr_in ( getsockname( $_[0]->[_SOCKET] ) ) + )[0]; + +# S2: + ( sockaddr_in ( getsockname( $_[0]->[_SOCKET] ) ) + )[0]; + +==> b1338.par <== +--continuation-indentation=7 +--extended-line-up-parentheses +--indent-columns=6 +--maximum-line-length=57 +--paren-vertical-tightness=2 +--space-function-paren +--weld-nested-containers + ==> b140.in <== $cmd[ $i ]=[ $s, $e, $cmd, \@hunk, $i ] ; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 79ab63b1..f7242adc 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -8738,6 +8738,18 @@ sub weld_nested_containers { my $ris_asub_block = $self->[_ris_asub_block_]; my $rOpts_asbl = $rOpts->{'opening-anonymous-sub-brace-on-new-line'}; + # Setup hash needed for RULE 2B involving -lp -wn -vt=2 + # Note: this could be changed in the future to include -vt=1 and -vt=2 + # but for now only -vt=2 has caused instabilities with -wn. + my %no_weld_to_one_line_container; + if ($rOpts_line_up_parentheses) { + foreach ( keys %opening_vertical_tightness ) { + if ( $opening_vertical_tightness{$_} == 2 ) { + $no_weld_to_one_line_container{$_} = 1; + } + } + } + # Find nested pairs of container tokens for any welding. my $rnested_pairs = $self->find_nested_pairs(); @@ -9137,6 +9149,19 @@ EOM $do_not_weld_rule = '2A'; } + # DO-NOT-WELD RULE 2B: Turn off welding to a *one-line container for* an + # opening token which uses both -lp indentation and -vt=2. See issue + # b1338. Also see related issue b1183 involving welds and -vt>0. + if ( !$do_not_weld_rule + && %no_weld_to_one_line_container + && $iline_io == $iline_ic + && $no_weld_to_one_line_container{$token_oo} + && !$rblock_type_of_seqno->{$outer_seqno} + && !$ris_excluded_lp_container->{$outer_seqno} ) + { + $do_not_weld_rule = '2B'; + } + # DO-NOT-WELD RULE 3: # Do not weld if this makes our line too long. # Use a tolerance which depends on if the old tokens were welded -- 2.39.5