]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix error check caused by -wn -iscl, case c058
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 14 Aug 2021 22:46:26 +0000 (15:46 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 14 Aug 2021 22:46:26 +0000 (15:46 -0700)
README.md
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index bac1300b5cf719a48886b0ec582756d6e975bbdd..003724db26d0d31b690f65bb3352b630db5b43e9 100644 (file)
--- 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)
index 4f935df83cd1f91f4e26c1f6e6cff3fa8a848ecc..a3c76d464f14c7cfeff2a01f7b8852960820e403 100644 (file)
@@ -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();
index 95113ace5870999b79030837d2645e6abbdb76d2..c06df8748853991c55548c4cad36ae2a42a682bb 100644 (file)
@@ -2,6 +2,15 @@
 
 =over 4
 
+=item B<Fix error check caused by -wn -iscl, case c058>
+
+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<Fix formatting instability, b1193>
 
 Testing with random parameters produced unstable formatting