forked from schacon/perl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[perl #86136] Downgrade sort {my $a} to a warning
The code in toke.c for detecting lexical $a or $b used in a comparison in a sort block was simply horrible. If the last-used named list or unary op (PL_last_lop_op) was sort, then it would scan for <=> or cmp anywhere on the current line of code. That meant that, although this would die: my $a; sort { $a <=> $b } () This would do the wrong thing without complaint: my $a; sort { print; $a <=> $b } () And this would die, completely gratuitously: my $a; sort @t; $a + $cmp; Since perl is only guessing that lexical $a or $b *might* have been used accidentally, this should be a warning, and certainly not an error. Also, scanning the source code like that for <=> (even inside a string!) can never work. One would have to parse it and examine the resulting op tree. In fact, since we *are* parsing it anyway, we *can* examine the op tree. So that’s exactly what this commit does. Based on the existing behav- iour, but with far fewer false positives, it checks for a cmp or <=> op as the last statement of a sort block and warns about any operand that is a lexical $a or $b.
- Loading branch information
Father Chrysostomos
committed
Jul 4, 2012
1 parent
449d128
commit 271c8bd
Showing
4 changed files
with
151 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters