develooper Front page | perl.perl5.porters | Postings from October 2014

[perl #121374] Wrong line number in signature errors

Thread Previous
From: via RT
October 27, 2014 22:05
[perl #121374] Wrong line number in signature errors
Message ID:
On Tue Sep 23 19:16:23 2014, sprout wrote:
> Getting the right line number means munging the op tree to use caller
> or doing something more sneaky like omitting nextstate ops (harder to
> get right, but should run faster).
> The code in question is at the bottom of toke.c.  My brain is too full
> to do it right now.

Here's a patch to do it the easy way. Instead of

  die "Too many arguments in subroutine" if @_ > 1;

it generates

  die sprintf "Too many arguments in subroutine at %s line %d.\n", (caller)[1, 2] if @_ > 1;

What's missing is tests for it. I could
  - create a new test file
  - add 2 or 3 tests to t/op/signatures.t
  - convert the existing tests in t/op/signatures.t from string eval to block eval and do an exact comparison on $@

t/op/signatures.t has a ton of tests that look like

sub t006 ($a) { $a || "z" }
is prototype(\&t006), undef;
is eval("t006()"), undef;
like $@, qr/\AToo few arguments for subroutine at/;
is eval("t006(0)"), "z";
is eval("t006(456)"), 456;
is eval("t006(456, 789)"), undef;
like $@, qr/\AToo many arguments for subroutine at/;

As far as I can tell there's no reason this should use a string eval. With block eval I'd get predictable filenames (i.e. not "(eval 123)") in the error messages, so I could write 'is $@, "..."' instead of 'like'.

... Or I could change all of those to qr/\AToo many arguments for subroutine at \(eval \d+) line 1\.$/. That would keep the string eval but make sure the reported location refers to the call.


via perlbug:  queue: perl5 status: open

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About