From 5a5a4df7fd09e79205f8a77b4213b15da9223d6a Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 1 Aug 2024 07:18:26 -0700 Subject: [PATCH] fix issue c382 'sort mycmp @array' triggered an incorrect warning if mycmp had prototype () --- lib/Perl/Tidy/Formatter.pm | 6 +++--- lib/Perl/Tidy/Tokenizer.pm | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 85aaaa31..dc39982c 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -4646,11 +4646,11 @@ EOM $right_bond_strength{'&&'} = NOMINAL; $left_bond_strength{'&&'} = $left_bond_strength{'||'} + 0.1; - # set strength of ^^ above && and ||. See git157. Note that: + # set strength of ^^ between && and ||. See git157. # "1 || 0 ^^ 0 || 1" = true, so ^^ is stronger than || - # "1 && 0 ^^ 1 = true, so ^^ is stronger than && + # "1 ^^ 1 && 0" = true, so && is stronger than ^^ $right_bond_strength{'^^'} = NOMINAL; - $left_bond_strength{'^^'} = $left_bond_strength{'||'} + 0.15; + $left_bond_strength{'^^'} = $left_bond_strength{'||'} + 0.05; $left_bond_strength{';'} = VERY_STRONG; $right_bond_strength{';'} = VERY_WEAK; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 0ff5331b..e633b06f 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -7811,10 +7811,6 @@ sub scan_bare_identifier_do { $self->report_v_string($tok); } - elsif ( $ris_constant->{$package}{$sub_name} ) { - $type = 'C'; - } - # bareword after sort has implied empty prototype; for example: # @sorted = sort numerically ( 53, 29, 11, 32, 7 ); # This has priority over whatever the user has specified. @@ -7824,6 +7820,12 @@ sub scan_bare_identifier_do { $type = 'Z'; } + # issue c382: this elsif statement moved from above because + # previous check for type 'Z' after sort has priority. + elsif ( $ris_constant->{$package}{$sub_name} ) { + $type = 'C'; + } + # Note: strangely, perl does not seem to really let you create # functions which act like eval and do, in the sense that eval # and do may have operators following the final }, but any operators -- 2.39.5