Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/perl5Public

Commit46adb82

Browse files
committed
Undefined subroutine &%s called, close to label '%s'
#17839 requested a compile-timewarning for the situation whereby a single colon is accdentally typedas 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 thestash at runtime, this falls somewhere between very difficult andimpossible. As an alternative, some enhanced fatal error wording wasrequested 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 fromother errors at runtime - such as the target subroutine not beingpresent at all - is also nigh on impossible. The hope is that theerror message will give some additional clue when the error is theresult of a typo, without distracting the user in all other cases.
1 parent0bed19a commit46adb82

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

‎pod/perldelta.pod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ and L</New Warnings>
260260

261261
=item *
262262

263+
L<Undefined subroutine &%s called, close to label '%s'|perldiag/"Undefined subroutine &%s called, close to label '%s'">
264+
265+
(F) The subroutine indicated hasn't been defined, or if it was, it has
266+
since been undefined.
267+
268+
This error could also indicate a mistyped package separator, when a
269+
single colon was typed instead of two colons. For example, C<Foo:bar()>
270+
would be parsed as the label C<Foo> followed by an unqualified function
271+
name: C<foo: bar()>.
272+
273+
=item *
274+
263275
XXX L<message|perldiag/"message">
264276

265277
=back

‎pod/perldiag.pod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,6 +6820,16 @@ Perhaps it's in a different package? See L<perlfunc/sort>.
68206820
(F) The subroutine indicated hasn't been defined, or if it was, it has
68216821
since been undefined.
68226822

6823+
=item Undefined subroutine &%s called, close to label '%s'
6824+
6825+
(F) The subroutine indicated hasn't been defined, or if it was, it has
6826+
since been undefined.
6827+
6828+
This error could also indicate a mistyped package separator, when a
6829+
single colon was typed instead of two colons. For example, C<Foo:bar()>
6830+
would be parsed as the label C<Foo> followed by an unqualified function
6831+
name: C<foo: bar()>.
6832+
68236833
=item Undefined subroutine called
68246834

68256835
(F) The anonymous subroutine you're trying to call hasn't been defined,

‎t/lib/croak/pp_hot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ Undefined subroutine &main::foo called at - line 3.
4545
&$foosub;
4646
EXPECT
4747
Undefined subroutine &main::foo called at - line 2.
48+
########
49+
# NAME package separator typo, creating a label by accident
50+
package BEEP;
51+
sub boop;
52+
package main;
53+
BEEP:boop();
54+
EXPECT
55+
Undefined subroutine &main::boop called, close to label 'BEEP' at - line 4.
56+
4857
########
4958
# NAME calling undef scalar
5059
&{+undef};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp