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

[perl #121374] Wrong line number in signature errors

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
October 27, 2014 22:52
Subject:
[perl #121374] Wrong line number in signature errors
Message ID:
rt-4.0.18-8057-1414450329-1997.121374-15-0@perl.org
On Mon Oct 27 15:05:43 2014, mauke- wrote:
> 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;

Thank you for the patch.

> 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 $@
> 
> Explanation:
> 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.
> 
> Suggestions?

Another approach is to add more tests to t/lib/croak/toke.

Do it whichever way makes it easiest for you.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=121374

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About