]> git.donarmstrong.com Git - perltidy.git/commitdiff
Avoid welding at sort/map/grep paren calls
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Apr 2021 03:45:30 +0000 (20:45 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Apr 2021 03:45:30 +0000 (20:45 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 6ef9eeca89f6cf4753cd06cf01444eb3674cfe5c..38aad9185039bfd499595b32ed186643296c0ef2 100644 (file)
@@ -3841,7 +3841,7 @@ EOM
             # Sixth Approximation. Welds.
             #---------------------------------------------------------------
 
-            # Do not allow a break within welds,
+            # Do not allow a break within welds
             if ( $seqno && $total_weld_count ) {
                 if ( $self->weld_len_right( $seqno, $type ) ) {
                     $strength = NO_BREAK;
@@ -6940,6 +6940,7 @@ sub find_nested_pairs {
         #        ^--K_o_o                                             ^--K_i_o
         #       @array) )
         my $Kn_first = $K_outer_opening;
+        my $Kn_last_nonblank;
         for (
             my $Kn = $K_outer_opening + 1 ;
             $Kn <= $K_inner_opening ;
@@ -6949,6 +6950,7 @@ sub find_nested_pairs {
             next if ( $rLL->[$Kn]->[_TYPE_] eq 'b' );
             if ( !$nonblank_count )        { $Kn_first = $Kn }
             if ( $Kn eq $K_inner_opening ) { $nonblank_count++; last; }
+            $Kn_last_nonblank = $Kn;
 
             # skip chain of identifier tokens
             my $last_type    = $type;
@@ -6961,6 +6963,18 @@ sub find_nested_pairs {
             last if ( $nonblank_count > 2 );
         }
 
+        # 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)
+            && $rLL->[$K_inner_opening]->[_TOKEN_] eq '('
+            && $rLL->[$Kn_last_nonblank]->[_TYPE_] eq 'k' )
+        {
+            my $token = $rLL->[$Kn_last_nonblank]->[_TOKEN_];
+
+            # Turn off welding at sort/map/grep (
+            if ( $is_sort_map_grep{$token} ) { $nonblank_count = 10 }
+        }
+
         if (
 
             # adjacent opening containers, like: do {{
@@ -22116,4 +22130,3 @@ sub wrapup {
 
 } ## end package Perl::Tidy::Formatter
 1;
-
index e69cf02cde73f03774fac9ac7a479afb4422293e..e0dc76b2a0cd219fe5d5c445c54b80004bd761d4 100644 (file)
@@ -2,6 +2,17 @@
 
 =over 4
 
+=item B<Avoid welding at sort/map/grep paren calls>
+
+Random testing produced several cases of unstable welds in which the inner
+container something like 'sort ('.  The problem was that there are special
+rules which prevent a break following such a paren.  The problem was fixed by
+preventing welds at these locations.
+
+This update fixes cases b1077 b1092 b1093 b1094 b1104 b1105 b1108.
+
+17 Apr 2021.
+
 =item B<Fix issue git#62>
 
 This fixes issue git #62.  A similar issue for the % operator was fixed.