From: Steve Hancock Date: Sat, 14 Aug 2021 22:46:26 +0000 (-0700) Subject: Fix error check caused by -wn -iscl, case c058 X-Git-Tag: 20210717.02~46 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5a1388652bb821efc759bb1c29613b858930ba52;p=perltidy.git Fix error check caused by -wn -iscl, case c058 --- diff --git a/README.md b/README.md index bac1300b..003724db 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# BUILD STATUS +# Build Status * [![Build Status](https://travis-ci.com/perltidy/perltidy.svg?branch=master)](https://travis-ci.com/perltidy/perltidy) * [CPAN Testers](https://www.cpantesters.org/distro/P/Perl-Tidy.html) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 4f935df8..a3c76d46 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -7472,6 +7472,7 @@ sub find_nested_pairs { # @array) ) my $Kn_first = $K_outer_opening; my $Kn_last_nonblank; + my $saw_comment; for ( my $Kn = $K_outer_opening + 1 ; $Kn <= $K_inner_opening ; @@ -7486,7 +7487,8 @@ sub find_nested_pairs { # skip chain of identifier tokens my $last_type = $type; my $last_is_name = $is_name; - $type = $rLL->[$Kn]->[_TYPE_]; + $type = $rLL->[$Kn]->[_TYPE_]; + if ( $type eq '#' ) { $saw_comment = 1; last } $is_name = $is_name_type->{$type}; next if ( $is_name && $last_is_name ); @@ -7494,6 +7496,9 @@ sub find_nested_pairs { last if ( $nonblank_count > 2 ); } + # Do not weld across a comment .. fix for c058. + next if ($saw_comment); + # Patch for b1104: do not weld to a paren preceded by sort/map/grep # because the special line break rules may cause a blinking state if ( defined($Kn_last_nonblank) @@ -10851,16 +10856,20 @@ EOM return unless ( $max_index_to_go >= 0 ); - # Exception 1: Do not end line in a weld - return - if ( $total_weld_count - && $self->[_rK_weld_right_]->{ $K_to_go[$max_index_to_go] } ); + # Exceptions when a line does not end with a comment... (fixes c058) + if ( $types_to_go[$max_index_to_go] ne '#' ) { - # Exception 2: just set a tentative breakpoint if we might be in a - # one-line block - if ( $index_start_one_line_block != UNDEFINED_INDEX ) { - $self->set_forced_breakpoint($max_index_to_go); - return; + # Exception 1: Do not end line in a weld + return + if ( $total_weld_count + && $self->[_rK_weld_right_]->{ $K_to_go[$max_index_to_go] } ); + + # Exception 2: just set a tentative breakpoint if we might be in a + # one-line block + if ( $index_start_one_line_block != UNDEFINED_INDEX ) { + $self->set_forced_breakpoint($max_index_to_go); + return; + } } $self->flush_batch_of_CODE(); diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 95113ace..c06df874 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,15 @@ =over 4 +=item B + +Testing with random parameters triggered an an internal error check. This was +caused by a recent coding change which allowed a weld across a side comment. +The problem was in the development version, not in the latest released version, +and is fixed with this update. This closes issue c058. + +14 Aug 2021. + =item B Testing with random parameters produced unstable formatting