From 89ba0d4bda4a0a5d5827b2bc87ddab0649cfb785 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 10 Sep 2020 15:29:23 -0700 Subject: [PATCH] fixed very rare fault found with automated testing --- lib/Perl/Tidy/Formatter.pm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 5d8356d4..c043fb1c 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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(); } } -- 2.39.5