New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong line number reported for sort subroutine? (Argument "a" isn't numeric in numeric comparison (<=>) at ... line ...) #17110
Comments
From Ulrich.Windl@rz.uni-regensburg.deHi! I think this is a bug in perl 5.18.2 (as shipped in SLES12 SP4): Debugging a sort routine I wrote myself I get an error that I don't understand, most likely because the line number reported (maybe even the whole error message) is wrong: First the effect (generic_sort is my sorting routine): DB<1> x generic_sort('', 'a') Then, even more confusing, I wrote a simpler test caser of my routine, named "_sort" where I deliberately forced an error: DB<3> x _sort('', 'a') So what you see is that in the first case the line reported cannot trigger the error; even the lines around it can't. Here are the relevant lines from the source (prefixed by the line numbers): 15 require 5.018_000; 129 sub generic_sort(@) 171 sub _sort(@) The print in line 132 was added AFTER I had observed the error. Before adding line 132, the error line reported also was 132. More obscure when I set a breakpoint at line 132, and then step through: P.S.: I did not post my sorting routine, as the code is probably not correct yet, but still the bug described does not make it easier for me to debug and fix.
Platform: Characteristics of this binary (from libperl): |
From @tonycozOn Thu, 25 Jul 2019 01:20:48 -0700, Ulrich.Windl@rz.uni-regensburg.de wrote:
Could your sort comparison block be returning "" ? $ perl5.18.3 -wle 'my @x = sort { "" } qw(1 2 3)' Tony |
The RT System itself - Status changed from 'new' to 'open' |
From Ulrich.Windl@rz.uni-regensburg.de
It could be that some if..else branch was incomplete and did not return an explicit value. The code now looks like this: return sub ($$) { while ($result != 0) { sub generic_sort(@) return sort { $cmp->($a, $b) } @_; Note: It may be less efficient, but at least it works and is debuggable ;-)
|
From @tonycozOn Tue, 06 Aug 2019 00:32:16 -0700, Ulrich.Windl@rz.uni-regensburg.de wrote:
Do you still consider this an issue? Note that perl isn't complaining about a numeric comparison in your generic_sort() case, but does in the _sort() case, so I do think it was the return value of the sort block causing the problem. In which case the line number is only off by one, possibly because the parser is looking ahead. Tony |
From Ulrich.Windl@rz.uni-regensburg.de
Well, I think the original error message with the (wrong) line number is confusing a lot, just as the attempt to single-step the code in the debugger was. Having to use a named subroutine just to debug the case seems non-optimal. |
Migrated from rt.perl.org#134312 (status was 'open')
Searchable as RT134312$
The text was updated successfully, but these errors were encountered: