]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1285, b1286; rare -lp instability
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Jan 2022 00:26:57 +0000 (16:26 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 11 Jan 2022 00:26:57 +0000 (16:26 -0800)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index c0af63ef563bbcc5667a044a440016151fc28e67..3d4c01cab84c380d4052e196376bfe768fc9ab74 100644 (file)
@@ -8824,6 +8824,29 @@ use overload
 --paren-vertical-tightness=2
 --weld-nested-containers
 
+==> b1285.in <==
+foreach $func (
+        @{$Win32API::Registry::EXPORT_TAGS{FuncA}
+        },
+        @{$Win32API::Registry::EXPORT_TAGS{FuncW}
+        }
+          );
+
+foreach $func (
+    @{$Win32API::Registry::EXPORT_TAGS{FuncA}
+    },
+    @{    $Win32API::Registry::EXPORT_TAGS{FuncW}
+    }
+          );
+
+
+==> b1285.par <==
+--brace-vertical-tightness=2
+--continuation-indentation=10
+--extended-line-up-parentheses
+--indent-columns=2
+--maximum-line-length=49
+
 ==> b1287.in <==
     $" < 2 ?
             $_[ $/ ][ $. ] |= 1 << $" :
index e93362cb12a254d21465b943a32f5f4be431ed9f..8c638ec1e40391aeea4ef81dd9d1e1fe456dc49b 100644 (file)
@@ -20454,6 +20454,8 @@ sub get_available_spaces_to_go {
 
 {    ## begin closure set_lp_indentation
 
+    use constant DEBUG_LP => 0;
+
     # Stack of -lp index objects which survives between batches.
     my $rLP;
     my $max_lp_stack;
@@ -20903,42 +20905,52 @@ EOM
                       : undef;
                 }
 
-                # initialization on empty stack..
                 $in_lp_mode = $rLP->[$max_lp_stack]->[_lp_object_];
+
+                #-----------------------------------------------
+                # Initialize indentation spaces on empty stack..
+                #-----------------------------------------------
                 if ( $max_lp_stack == 0 ) {
                     $space_count = $level * $rOpts_indent_columns;
                 }
 
-                # if this is a BLOCK, add the standard increment
-                elsif ($last_nonblank_block_type) {
-                    $space_count += $standard_increment;
-                }
+                #----------------------------------------
+                # Add the standard space increment if ...
+                #----------------------------------------
+                elsif (
 
-                # if this is not a sequenced item, add the standard increment
-                elsif ( !$last_nonblank_seqno ) {
-                    $space_count += $standard_increment;
-                }
+                    # if this is a BLOCK, add the standard increment
+                    $last_nonblank_block_type
 
-                # add the standard increment for containers excluded by user
-                # rules or which contain here-docs or multiline qw text
-                elsif ( defined($last_nonblank_seqno)
-                    && $ris_excluded_lp_container->{$last_nonblank_seqno} )
-                {
-                    $space_count += $standard_increment;
-                }
+                    # or if this is not a sequenced item
+                    || !$last_nonblank_seqno
 
-                # if last nonblank token was not structural indentation,
-                # just use standard increment
-                elsif ( $last_nonblank_type ne '{' ) {
-                    $space_count += $standard_increment;
-                }
+                    # or this continer is excluded by user rules
+                    # or contains here-docs or multiline qw text
+                    || defined($last_nonblank_seqno)
+                    && $ris_excluded_lp_container->{$last_nonblank_seqno}
+
+                    # or if last nonblank token was not structural indentation
+                    || $last_nonblank_type ne '{'
+
+                    # and do not start -lp under stress .. fixes b1244, b1255
+                    || !$in_lp_mode && $level >= $lp_cutoff_level
+
+                  )
+                {
 
-                # do not start -lp under stress .. fixes b1244, b1255
-                elsif ( !$in_lp_mode && $level >= $lp_cutoff_level ) {
+                    # If we have entered lp mode, use the top lp object to get
+                    # the current indentation spaces because it may have
+                    # changed.  Fixes b1285, b1286.
+                    if ($in_lp_mode) {
+                        $space_count = $in_lp_mode->get_spaces();
+                    }
                     $space_count += $standard_increment;
                 }
 
-                # otherwise use the space to the first non-blank level change
+                #---------------------------------------------------------------
+                # -lp mode: try to use space to the first non-blank level change
+                #---------------------------------------------------------------
                 else {
 
                     # see how much space we have available
@@ -21013,7 +21025,9 @@ EOM
                     }
                 }
 
-                # update state, but not on a blank token
+                #-------------------------------------------
+                # update the state, but not on a blank token
+                #-------------------------------------------
                 if ( $type ne 'b' ) {
 
                     if ( $rLP->[$max_lp_stack]->[_lp_object_] ) {
@@ -21064,6 +21078,13 @@ EOM
                             K_begin_line     => $K_begin_line,
                         );
 
+                        DEBUG_LP && do {
+                            my $tok_beg = $rLL->[$K_begin_line]->[_TOKEN_];
+                            print STDERR <<EOM;
+DEBUG_LP: Created object at tok=$token type=$type for seqno $align_seqno level=$level ci=$ci_level spaces=$space_count avail=$available_spaces kbeg=$K_begin_line tokbeg=$tok_beg lp=$lp_position_predictor
+EOM
+                        };
+
                         if ( $level >= 0 ) {
                             $rlp_object_list->[$max_lp_object_list] =
                               $lp_object;