Skip to content

Commit 7e2d91e

Browse files
committed
toke.c: deprecation warning for ' as a package separator
First stage of RFC 0015. This also changes the warning for ' as package separator in quoted strings to also be a deprecation warning.
1 parent a36fec4 commit 7e2d91e

File tree

14 files changed

+142
-72
lines changed

14 files changed

+142
-72
lines changed

embed.fnc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3366,7 +3366,8 @@ EXpx |char * |scan_word |NN char *s \
33663366
|NN char *dest \
33673367
|STRLEN destlen \
33683368
|int allow_package \
3369-
|NN STRLEN *slp
3369+
|NN STRLEN *slp \
3370+
|bool warn_tick
33703371
EXpxR |char * |skipspace_flags|NN char *s \
33713372
|U32 flags
33723373
EdXxp |bool |validate_proto |NN SV *name \

embed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@
16971697
# define reg_temp_copy(a,b) Perl_reg_temp_copy(aTHX_ a,b)
16981698
# define report_uninit(a) Perl_report_uninit(aTHX_ a)
16991699
# define scan_str(a,b,c,d,e) Perl_scan_str(aTHX_ a,b,c,d,e)
1700-
# define scan_word(a,b,c,d,e) Perl_scan_word(aTHX_ a,b,c,d,e)
1700+
# define scan_word(a,b,c,d,e,f) Perl_scan_word(aTHX_ a,b,c,d,e,f)
17011701
# define skipspace_flags(a,b) Perl_skipspace_flags(aTHX_ a,b)
17021702
# define sv_magicext_mglob(a) Perl_sv_magicext_mglob(aTHX_ a)
17031703
# define sv_only_taint_gmagic Perl_sv_only_taint_gmagic

pod/perldiag.pod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4517,13 +4517,21 @@ C<sysread()>ing a file, or when seeking past the end of a scalar opened
45174517
for I/O (in anticipation of future reads and to imitate the behavior
45184518
with real files).
45194519

4520+
=item Old package separator "'" deprecated
4521+
4522+
(W deprecated, syntax) You used the old package separator "'" in a
4523+
variable, subroutine or package name. Support for the old package
4524+
separator will be removed in Perl 5.40.
4525+
45204526
=item Old package separator used in string
45214527

4522-
(W syntax) You used the old package separator, "'", in a variable
4528+
(W deprecated, syntax) You used the old package separator, "'", in a variable
45234529
named inside a double-quoted string; e.g., C<"In $name's house">. This
45244530
is equivalent to C<"In $name::s house">. If you meant the former, put
45254531
a backslash before the apostrophe (C<"In $name\'s house">).
45264532

4533+
Support for the old package separator will be removed in Perl 5.40.
4534+
45274535
=item %s() on unopened %s
45284536

45294537
(W unopened) An I/O operation was attempted on a filehandle that was

proto.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

t/comp/package.t

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!./perl
22

3+
BEGIN {
4+
@INC = qw(. ../lib);
5+
chdir 't' if -d 't';
6+
}
7+
38
print "1..14\n";
49

510
$blurfl = 123;
@@ -13,11 +18,14 @@ $bar = 4;
1318

1419
{
1520
package ABC;
21+
no warnings qw(syntax deprecated);
1622
$blurfl = 5;
1723
$main'a = $'b;
1824
}
19-
20-
$ABC'dyick = 6;
25+
{
26+
no warnings qw(syntax deprecated);
27+
$ABC'dyick = 6;
28+
}
2129
2230
$xyz = 2;
2331
@@ -28,10 +36,13 @@ $ABC = join(':', sort(keys %ABC::));
2836
if ('a' lt 'A') {
2937
print $xyz eq 'bar:main:new:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
3038
} else {
31-
print $xyz eq 'ABC:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
39+
print $xyz eq 'ABC:BEGIN:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
3240
}
33-
print $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
34-
print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
41+
print $ABC eq 'BEGIN:blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
42+
{
43+
no warnings qw(syntax deprecated);
44+
print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
45+
}
3546

3647
package ABC;
3748

t/comp/parser.t

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,14 @@ like($@, qr/BEGIN failed--compilation aborted/, 'BEGIN 7' );
367367
is(defined &zlonk, '', 'but no body defined');
368368
}
369369

370-
# [perl #113016] CORE::print::foo
371-
sub CORE'print'foo { 43 } # apostrophes intentional; do not tempt fate
372-
sub CORE'foo'bar { 43 }
373-
is CORE::print::foo, 43, 'CORE::print::foo is not CORE::print ::foo';
374-
is scalar eval "CORE::foo'bar", 43, "CORE::foo'bar is not an error";
370+
{
371+
no warnings;
372+
# [perl #113016] CORE::print::foo
373+
sub CORE'print'foo { 43 } # apostrophes intentional; do not tempt fate
374+
sub CORE'foo'bar { 43 }
375+
is CORE::print::foo, 43, 'CORE::print::foo is not CORE::print ::foo';
376+
is scalar eval "CORE::foo'bar", 43, "CORE::foo'bar is not an error";
377+
}
375378
376379
# bug #71748
377380
eval q{
@@ -448,8 +451,10 @@ END
448451
eval 's/${<<END}//';
449452
eval 's//${<<END}/';
450453
print "ok ", ++$test, " - unterminated here-docs in s/// in string eval\n";
451-
452-
sub 'Hello'_he_said (_);
454+
{
455+
no warnings qw(syntax deprecated);
456+
sub 'Hello'_he_said (_);
457+
}
453458
is prototype "Hello::_he_said", '_', 'initial tick in sub declaration';
454459
455460
{
@@ -471,11 +476,14 @@ is $pkg, 3, '[perl #114942] for my $foo()){} $foo';
471476
472477
# Check that format 'Foo still works after removing the hack from
473478
# force_word
474-
$test++;
475-
format 'one =
479+
{
480+
no warnings qw(syntax deprecated);
481+
$test++;
482+
format 'one =
476483
ok @<< - format 'foo still works
477484
$test
478485
.
486+
}
479487
{
480488
local $~ = "one";
481489
write();

t/lib/warnings/toke

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ use warnings 'syntax';
416416
() = "$foo'bar";
417417
() = "@foo'bar";
418418
() = "$#foo'bar";
419-
no warnings 'syntax' ;
419+
no warnings 'syntax', 'deprecated' ;
420420
() = "$foo'bar";
421421
() = "@foo'bar";
422422
() = "$#foo'bar";
@@ -439,7 +439,7 @@ use warnings 'syntax'; use utf8;
439439
() = "$fooл'barл";
440440
() = "@fooл'barл";
441441
() = "$#fooл'barл";
442-
no warnings 'syntax' ;
442+
no warnings 'syntax', 'deprecated' ;
443443
() = "$fooл'barл";
444444
() = "@fooл'barл";
445445
() = "$#fooл'barл";
@@ -451,6 +451,19 @@ Old package separator used in string at - line 4.
451451
Old package separator used in string at - line 5.
452452
(Did you mean "$#fooл\'barл" instead?)
453453
########
454+
# NAME deprecation of ' in names
455+
sub foo'bar { 1 }
456+
$a'b = 1;
457+
@a'c = ();
458+
%a'd = ();
459+
package a'e;
460+
EXPECT
461+
Old package separator "'" deprecated at - line 1.
462+
Old package separator "'" deprecated at - line 2.
463+
Old package separator "'" deprecated at - line 3.
464+
Old package separator "'" deprecated at - line 4.
465+
Old package separator "'" deprecated at - line 5.
466+
########
454467
# toke.c
455468
use warnings 'ambiguous' ;
456469
$a = ${time[2]};

t/op/method.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ sub OtherSouper::method { "Isidore Ropen, Draft Manager" }
253253
my @ret = $o->SUPER::method('whatever');
254254
::is $ret[0], $o, 'object passed to SUPER::method';
255255
::is $ret[1], 'whatever', 'argument passed to SUPER::method';
256-
@ret = $o->SUPER'method('whatever');
256+
{
257+
no warnings qw(syntax deprecated);
258+
@ret = $o->SUPER'method('whatever');
259+
}
257260
::is $ret[0], $o, "object passed to SUPER'method";
258261
::is $ret[1], 'whatever', "argument passed to SUPER'method";
259262
@ret = Saab->SUPER::method;

t/op/ref.t

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ is (join('', sort values %$anonhash2), 'BARXYZ');
265265
# Test bless operator.
266266

267267
package MYHASH;
268-
269-
$object = bless $main'anonhash2;
268+
{
269+
no warnings qw(syntax deprecated);
270+
$object = bless $main'anonhash2;
271+
}
270272
main::is (ref $object, 'MYHASH');
271273
main::is ($object->{ABC}, 'XYZ');
272274
@@ -290,7 +292,10 @@ sub mymethod {
290292
$string = "bad";
291293
$object = "foo";
292294
$string = "good";
293-
$main'anonhash2 = "foo";
295+
{
296+
no warnings qw(syntax deprecated);
297+
$main'anonhash2 = "foo";
298+
}
294299
$string = "";
295300

296301
DESTROY {
@@ -307,7 +312,10 @@ package OBJ;
307312

308313
@ISA = ('BASEOBJ');
309314

310-
$main'object = bless {FOO => 'foo', BAR => 'bar'};
315+
{
316+
no warnings qw(syntax deprecated);
317+
$main'object = bless {FOO => 'foo', BAR => 'bar'};
318+
}
311319
312320
package main;
313321
@@ -320,10 +328,13 @@ is ($object->doit("BAR"), 'bar');
320328
$foo = doit $object "FOO";
321329
main::is ($foo, 'foo');
322330
323-
sub BASEOBJ'doit {
324-
local $ref = shift;
325-
die "Not an OBJ" unless ref $ref eq 'OBJ';
326-
$ref->{shift()};
331+
{
332+
no warnings qw(syntax deprecated);
333+
sub BASEOBJ'doit {
334+
local $ref = shift;
335+
die "Not an OBJ" unless ref $ref eq 'OBJ';
336+
$ref->{shift()};
337+
}
327338
}
328339

329340
package UNIVERSAL;

t/op/sort.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ eval { @b = sort twoface 4,1 };
237237
cmp_ok(substr($@,0,4), 'eq', 'good', 'twoface eval');
238238

239239
eval <<'CODE';
240+
no warnings qw(deprecated syntax);
240241
my @result = sort main'Backwards 'one', 'two';
241242
CODE
242243
cmp_ok($@,'eq','',q(old skool package));

t/op/stash_parse_gv.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ foreach my $t (@tests) {
2323
my ( $sub, $name ) = @$t;
2424

2525
fresh_perl_is(
26-
qq[sub $sub { print qq[ok\n]} &{"$sub"}; my \$d = defined *{"foo$sub"} ],
26+
qq[no warnings qw(syntax deprecated); sub $sub { print qq[ok\n]} &{"$sub"}; my \$d = defined *{"foo$sub"} ],
2727
q[ok],
2828
{ switches => ['-w'] },
2929
$name

t/uni/package.t

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,23 @@ ok 1, "sanity check. If we got this far, UTF-8 in package names is legal.";
3434
$ㄅĽuṞfⳐ = 5;
3535
}
3636

37-
$압Ƈ'd읯ⱪ = 6; #'
38-
37+
{
38+
no warnings qw(syntax deprecated);
39+
$압Ƈ'd읯ⱪ = 6; #'
40+
}
41+
3942
$ꑭʑ = 2;
4043

4144
$ꑭʑ = join(':', sort(keys %ꑭʑ::));
4245
$압Ƈ = join(':', sort(keys %압Ƈ::));
4346

44-
::is $ꑭʑ, 'bar:ニュー:ꑭʑ:압Ƈ', "comp/stash.t test 1";
47+
::is $ꑭʑ, 'BEGIN:bar:ニュー:ꑭʑ:압Ƈ', "comp/stash.t test 1";
4548
::is $압Ƈ, "d읯ⱪ:ㄅĽuṞfⳐ", "comp/stash.t test 2";
46-
::is $main'ㄅĽuṞfⳐ, 123, "comp/stash.t test 3";
49+
50+
{
51+
no warnings qw(syntax deprecated);
52+
::is $main'ㄅĽuṞfⳐ, 123, "comp/stash.t test 3";
53+
}
4754
4855
package 압Ƈ;
4956

t/uni/variables.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ plan (tests => 66880);
4141
eval q<use strict; ${flark::fleem}>;
4242
is($@, '', q<${package::var} works>);
4343

44+
no warnings qw(syntax deprecated);
4445
local $@;
4546
eval q<use strict; ${fleem'flark}>;
4647
is($@, '', q<...as does ${package'var}>);

0 commit comments

Comments
 (0)