]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix git #105, v5.36 experimental for_list feature
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 27 Jul 2022 22:06:37 +0000 (15:06 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 27 Jul 2022 22:06:37 +0000 (15:06 -0700)
CHANGES.md
lib/Perl/Tidy/Tokenizer.pm
t/snippets/expect/git105.def [new file with mode: 0644]
t/snippets/git105.in [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets26.t

index 5faa68feda6acf1cd7b26a6347e04be06a5c16e9..740fd32e584259f3b628573b9d5183b7b4a1124b 100644 (file)
@@ -2,6 +2,9 @@
 
 ## 2022 06 13.02
 
+    - Fix for issue git #105, incorrect formatting with 5.36 experimental
+      for_list feature.
+
     - Fix for issue git #103. For parameter -b, or --backup-and-modify-in-place,
       the default backup method has been changed to preserve the inode value
       of the file being formatted.  If this causes a problem, the previous
index ecca17b3553a323b7ea5d72dcbf74be61d16ba59..a8fe9d52ae09e87cd0370f64ff919f008e547fda 100644 (file)
@@ -2436,7 +2436,15 @@ EOM
                 } ## end else [ if ( $last_last_nonblank_token...
             } ## end if ( $expecting == OPERATOR...
         }
-        $paren_type[$paren_depth] = $container_type;
+
+        # Do not update container type at ') ('; fix for git #105.  This will
+        # propagate the container type onward so that any subsequent brace gets
+        # correctly marked.  I have implemented this as a general rule, which
+        # should be safe, but if necessary it could be restricted to certain
+        # container statement types such as 'for'.
+        $paren_type[$paren_depth] = $container_type
+          if ( $last_nonblank_token ne ')' );
+
         ( $type_sequence, $indent_flag ) =
           increase_nesting_depth( PAREN, $rtoken_map->[$i_tok] );
 
diff --git a/t/snippets/expect/git105.def b/t/snippets/expect/git105.def
new file mode 100644 (file)
index 0000000..15514e9
--- /dev/null
@@ -0,0 +1,9 @@
+use v5.36;
+
+use experimental 'for_list';
+
+for my ( $k, $v ) ( 1, 2, 3, 4 ) {
+    say "$k:$v";
+}
+say 'end';
+
diff --git a/t/snippets/git105.in b/t/snippets/git105.in
new file mode 100644 (file)
index 0000000..15514e9
--- /dev/null
@@ -0,0 +1,9 @@
+use v5.36;
+
+use experimental 'for_list';
+
+for my ( $k, $v ) ( 1, 2, 3, 4 ) {
+    say "$k:$v";
+}
+say 'end';
+
index 03d937a54bed17d5183b94aad8f6fdddfca57e4b..20b4fb0868466c60d14a308b7cbb85a33ccc3df0 100644 (file)
 ../snippets26.t        git93.def
 ../snippets26.t        git93.git93
 ../snippets26.t        c139.def
+../snippets26.t        drc.def
+../snippets26.t        drc.drc
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets26.t        drc.def
-../snippets26.t        drc.drc
+../snippets26.t        git105.def
index 644dc5babc1a5f5d8df7c79988305d25cd5b8622..18483a3b4ba678de392f664483ae8c5f2269b503 100644 (file)
@@ -11,6 +11,7 @@
 #8 c139.def
 #9 drc.def
 #10 drc.drc
+#11 git105.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -102,6 +103,18 @@ sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
 
         'drc' => <<'----------',
 ignoreSpec( $file, "file",, \%spec,,, \%Rspec );
+----------
+
+        'git105' => <<'----------',
+use v5.36;
+
+use experimental 'for_list';
+
+for my ( $k, $v ) ( 1, 2, 3, 4 ) {
+    say "$k:$v";
+}
+say 'end';
+
 ----------
 
         'git93' => <<'----------',
@@ -428,6 +441,22 @@ ignoreSpec( $file, "file",, \%spec,,, \%Rspec );
 ignoreSpec( $file, "file", \%spec, \%Rspec );
 #10...........
         },
+
+        'git105.def' => {
+            source => "git105",
+            params => "def",
+            expect => <<'#11...........',
+use v5.36;
+
+use experimental 'for_list';
+
+for my ( $k, $v ) ( 1, 2, 3, 4 ) {
+    say "$k:$v";
+}
+say 'end';
+
+#11...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};