From: Steve Hancock Date: Mon, 30 Dec 2019 00:02:14 +0000 (-0800) Subject: fixed rt#131288 X-Git-Tag: 20200110~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e845caa36a3607bf39fe2a941e2f84244868f085;p=perltidy.git fixed rt#131288 --- diff --git a/CHANGES.md b/CHANGES.md index fb92cf5f..0f8d4d7f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 2019 12 03.01 + - Fixed issue RT#131288: parse error for un-prototyped constant function + followed by ternary. ## 2019 12 03 diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 77b77323..edc07aa9 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -2055,8 +2055,17 @@ sub prepare_for_a_new_file { { $is_pattern = 0; } + + # patch for RT#131288, user constant function without prototype + # last type is 'U' followed by ?. + elsif ( $last_nonblank_type =~ /^[FUY]$/ ) { + $is_pattern = 0; + } elsif ( $expecting == UNKNOWN ) { + # FIXME: Can a bare ? still be a pattern delimiter in modern + # versions of Perl? Need to research this and decide what + # to do. my $msg; ( $is_pattern, $msg ) = guess_if_pattern_or_conditional( $i, $rtokens, $rtoken_map, diff --git a/t/snippets/expect/rt131288.def b/t/snippets/expect/rt131288.def new file mode 100644 index 00000000..089bbb06 --- /dev/null +++ b/t/snippets/expect/rt131288.def @@ -0,0 +1,3 @@ +sub OptArgs2::STYLE_FULL { 3 } +$style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage', + 'usage: ' . $usage . "\n"; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 25f505b9..5f4afdc0 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -311,3 +311,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets16.t rt131288.def diff --git a/t/snippets/rt131288.in b/t/snippets/rt131288.in new file mode 100644 index 00000000..01fcf3c4 --- /dev/null +++ b/t/snippets/rt131288.in @@ -0,0 +1,2 @@ +sub OptArgs2::STYLE_FULL { 3 } +$style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage', 'usage: ' . $usage . "\n"; diff --git a/t/snippets16.t b/t/snippets16.t index ed36de83..3377c69a 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -16,6 +16,7 @@ #13 rt131115.rt131115 #14 ndsm1.def #15 ndsm1.ndsm +#16 rt131288.def # To locate test #13 you can search for its name or the string '#13' @@ -126,6 +127,11 @@ sub a { $uniq{$par} = 1; } } +---------- + + 'rt131288' => <<'----------', +sub OptArgs2::STYLE_FULL { 3 } +$style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage', 'usage: ' . $usage . "\n"; ---------- 'spp' => <<'----------', @@ -339,6 +345,16 @@ sub Numerically { $a <=> $b }; # trapped semicolon __; #15........... }, + + 'rt131288.def' => { + source => "rt131288", + params => "def", + expect => <<'#16...........', +sub OptArgs2::STYLE_FULL { 3 } +$style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage', + 'usage: ' . $usage . "\n"; +#16........... + }, }; my $ntests = 0 + keys %{$rtests};