]> git.donarmstrong.com Git - perltidy.git/commitdiff
added internal code consistency check
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 26 Apr 2020 13:20:35 +0000 (06:20 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 26 Apr 2020 13:20:35 +0000 (06:20 -0700)
lib/Perl/Tidy/Formatter.pm

index b72af3423be0c2f3a5d87e4acdd509dfd8a9fc5d..06c40cc27362fdbb97a537d8258db3fbf1a2f6c2 100644 (file)
@@ -7077,6 +7077,17 @@ sub copy_token_as_type {
         my $slevel                = $rtoken_vars->[_SLEVEL_];
         my $ci_level              = $rtoken_vars->[_CI_LEVEL_];
 
+       # 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.
+        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");
+            }
+        }
+
         ++$max_index_to_go;
         $K_to_go[$max_index_to_go]                     = $Ktoken_vars;
         $tokens_to_go[$max_index_to_go]                = $token;
@@ -7111,7 +7122,7 @@ sub copy_token_as_type {
         my $length = $rLL->[$Ktoken_vars]->[_TOKEN_LENGTH_];
 
         # FIXME: Patch for indent-only, in which the entire set of tokens is
-        # turned into type 'q'. Lengths have not been defined because sub
+        # turned into type 'q'. Lengths may have not been defined because sub
         # 'respace_tokens' is bypassed. We do not need lengths in this case,
         # but we will use the character count to have a defined value.  In the
         # future, it would be nicer to have 'respace_tokens' convert the lines