-
Notifications
You must be signed in to change notification settings - Fork 559
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
Undefined subroutine &%s called, close to label '%s' #22860
base: blead
Are you sure you want to change the base?
Conversation
01a4fbf
to
73a4618
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to see this split into two commits - the first to extract out the DIEes into a separate helper function, and the second to add the LABEL functionality.
I think the perldiag text (and perldelta) could be improved: give an actual example of the problem it's trying to flag, e.g. "Cfoo:bar() would be parsed as a label followed by an unqualified function name: C<foo: bar()>".
I'm somewhat twitchy that the message is generated even if the label doesn't immediately precede the function call but is merely in the same statement; E.g.
FOO: if ($x > 1 && foo()) { ... }
I'll make those changes now.
Yes, I'm in two minds about it for that reason too. If, on balance, it looks like this will add more confusion than clarity, there's no point in adding it. |
In `pp_entersub`, when trying to find the subroutine `CV` to execute, there are three nearby code paths that can result in a `DIE()`. This commit extracts the DIE() logic to a helper subroutine, `S_croak_undefined_subroutine`. This is partly in anticipation of additional warning logic, but also generally reduces the size of this hot function.
Perl#17839 requested a compile-time warning for the situation whereby a single colon is accdentally typed as a package separator when calling a function. For example: ``` package BOOP; sub beep; package main; BOOP:beep(); # Meant to be BOOP::beep(); ``` However, because of both Perl's syntax and the potential to populate the stash at runtime, this falls somewhere between very difficult and impossible. As an alternative, some enhanced fatal error wording was requested and these commits attempt to provide that. The above example would previously die with the message: ``` Undefined subroutine &main::beep called at ... line 4. ``` Now it dies with the message: ``` Undefined subroutine &main::beep called, close to label 'BOOP' at ... line 4. ``` For some of the same reasons mentioned, distinguishing this typo from other errors at runtime - such as the target subroutine not being present at all - is also nigh on impossible. The hope is that the error message will give some additional clue when the error is the result of a typo, without distracting the user in all other cases.
73a4618
to
46adb82
Compare
On Mon, Dec 16, 2024 at 01:43:30PM -0800, Richard Leach wrote:
I'll make those changes now.
Unless I'm misreading it, the 'detect label' code is actually part of the
"Move pp_entersub DIE() code into S_croak_undefined_subroutine" commit.
> I'm somewhat twitchy that the message is generated even if the label doesn't immediately precede the function call but is merely in the same statement;
Yes, I'm in two minds about it for that reason too. If, on balance, it looks like this will add more confusion than clarity, there's no point in adding it.
Perhaps the warning text should only added for the case where
PL_curcop->op_next == PL_op
?
…--
A power surge on the Bridge is rapidly and correctly diagnosed as a faulty
capacitor by the highly-trained and competent engineering staff.
-- Things That Never Happen in "Star Trek" #9
|
#17839 requested a compile-time
warning for the situation whereby a single colon is accdentally typed
as a package separator when calling a function. For example:
However, because of both Perl's syntax and the potential to populate the
stash at runtime, this falls somewhere between very difficult and
impossible. As an alternative, some enhanced fatal error wording was
requested and these commits attempt to provide that.
The above example would previously die with the message:
Now it dies with the message:
For some of the same reasons mentioned, distinguishing this typo from
other errors at runtime - such as the target subroutine not being
present at all - is also nigh on impossible. The hope is that the
error message will give some additional clue when the error is the
result of a typo, without distracting the user in all other cases.
As part of these commits, some common
DIE()
calls inpp_entersub
wereextracted into a new helper function,
S_croak_undefined_subroutine
, toavoid adding (and slightly reduce) cold code bloating in
pp_entersub
.