From: Steve Hancock Date: Wed, 27 Jul 2022 22:06:37 +0000 (-0700) Subject: fix git #105, v5.36 experimental for_list feature X-Git-Tag: 20220613.03~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=28a4946977719faa37982cf7a54e3c56041d9fc3;p=perltidy.git fix git #105, v5.36 experimental for_list feature --- diff --git a/CHANGES.md b/CHANGES.md index 5faa68fe..740fd32e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index ecca17b3..a8fe9d52 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 index 00000000..15514e90 --- /dev/null +++ b/t/snippets/expect/git105.def @@ -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 index 00000000..15514e90 --- /dev/null +++ b/t/snippets/git105.in @@ -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/packing_list.txt b/t/snippets/packing_list.txt index 03d937a5..20b4fb08 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -354,6 +354,8 @@ ../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 @@ -494,5 +496,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets26.t drc.def -../snippets26.t drc.drc +../snippets26.t git105.def diff --git a/t/snippets26.t b/t/snippets26.t index 644dc5ba..18483a3b 100644 --- a/t/snippets26.t +++ b/t/snippets26.t @@ -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};