]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed very rare fault found with automated testing
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Sep 2020 22:29:23 +0000 (15:29 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 10 Sep 2020 22:29:23 +0000 (15:29 -0700)
lib/Perl/Tidy/Formatter.pm

index 5d8356d4f78f26d3e1e77a96f6b4a8574e575d3f..c043fb1cab17cf2b939872be9837bd3214d27b3f 100644 (file)
@@ -7463,14 +7463,21 @@ sub copy_token_as_type {
         # We had to wait until now for reasons explained in sub 'write_line'.
         if ( $level < 0 ) { $level = 0 }
 
-        # Programming check: The K indexes in the batch must be a continuous
-        # sequence of the global token array.  If this relationship fails we
-        # are in danger of losing data.  An error here implies an error in
-        # a recent programming change.
+        # Check for emergency flush...
+       # The K indexes in the batch must always be a continuous sequence of
+       # the global token array.  The batch process programming assumes this.
+       # If storing this token would cause this relation to fail we must dump
+       # the current batch before storing the new token.  It is extremely rare
+       # for this to happen. One known example is the following two-line snippet
+       # when run with parameters
+        # --noadd-newlines  --space-terminal-semicolon:
+        #    if ( $_ =~ /PENCIL/ ) { $pencil_flag= 1 } ; ;
+        #    $yy=1;
+
         if ( defined($max_index_to_go) && $max_index_to_go >= 0 ) {
             my $Klast = $K_to_go[$max_index_to_go];
             if ( $Ktoken_vars != $Klast + 1 ) {
-                Fault("Unexpected break in K values: $Ktoken_vars != $Klast+1");
+                 $self->flush_batch_of_CODE();
             }
         }