From 2dc78664124f51814246e5b3da10c8a9f5fe2726 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Fri, 26 Nov 2010 15:53:56 +0000 Subject: [PATCH] Make my $pi := 4; a syntax error. Previously it interpreted := as an empty attribute list, and issued a deprecation warning. This change permits := to be used as a binding operator. --- dist/B-Deparse/t/deparse.t | 3 ++- pod/perldelta.pod | 16 +++++++++---- pod/perldiag.pod | 14 ++++++----- t/lib/warnings/toke | 59 ---------------------------------------------- t/op/attrs.t | 57 ++++++++++++++++++++++++++++++++++++++++++-- toke.c | 3 ++- 6 files changed, 79 insertions(+), 73 deletions(-) diff --git a/dist/B-Deparse/t/deparse.t b/dist/B-Deparse/t/deparse.t index 3ae14e9..38ce876 100644 --- a/dist/B-Deparse/t/deparse.t +++ b/dist/B-Deparse/t/deparse.t @@ -619,7 +619,8 @@ foreach (0..3) { # no attribute list my $pi = 4; #### -# := empty attribute list +# SKIP ?$] > 5.013006 && ":= is now a syntax error" +# := treated as an empty attribute list no warnings; my $pi := 4; >>>> diff --git a/pod/perldelta.pod b/pod/perldelta.pod index d85f1ba..2a35cc4 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -67,12 +67,20 @@ L section. =head1 Incompatible Changes -XXX For a release on a stable branch, this section aspires to be: +=head2 Attempting to use C<:=> as an empty attribute list is now a syntax error - There are no changes intentionally incompatible with 5.XXX.XXX. If any - exist, they are bugs and reports are welcome. +Previously C was exactly equivalent to C, +with the C<:> being treated as the start of an attribute list, ending before +the C<=>. The use of C<:=> to mean C<: => was deprecated in 5.12.0, and is now +a syntax error. This will allow the future use of C<:=> as a new token. -[ List each incompatible change as a =head2 entry ] +We find no Perl 5 code on CPAN using this construction, outside the core's +tests for it, so we believe that this change will have very little impact on +real-world codebases. + +If it is absolutely necessary to have empty attribute lists (for example, +because of a code generator) then avoid the warning by adding a space +before the C<=>. =head1 Deprecations diff --git a/pod/perldiag.pod b/pod/perldiag.pod index c186919..7250057 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4991,13 +4991,15 @@ modifier is not presently meaningful in substitutions. use the /g modifier. Currently, /c is meaningful only when /g is used. (This may change in the future.) -=item Use of := for an empty attribute list is deprecated +=item Use of := for an empty attribute list is not allowed -(D deprecated) The construction C currently -parses correctly in perl, being equivalent to C -(applying an empty attribute list to C<$x>). This useless -construct is now deprecated, so C<:=> can be reclaimed as a new -operator in the future. +(F) The construction C used to parse as equivalent to +C (applying an empty attribute list to C<$x>). +This construct was deprecated in 5.12.0, and has now been made a syntax +error, so C<:=> can be reclaimed as a new operator in the future. + +If you need an empty attribute list, for example in a code generator, add +a space before the C<=>. =item Use of ?PATTERN? without explicit operator is deprecated diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index 7096620..5468ef0 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -909,65 +909,6 @@ Possible unintended interpolation of $\ in regex at - line 3. Possible unintended interpolation of $\ in regex at - line 5. ######## # toke.c -use feature 'state'; -# This one is fine as an empty attribute list -my $holy_Einstein : = ''; -# This one is deprecated -my $krunch := 4; -our $FWISK_FWISK_FWIZZACH_FWACH_ZACHITTY_ZICH_SHAZZATZ_FWISK := ''; -state $thump := 'Trumpets'; -# Lather rinse repeat in my usual obsessive style -my @holy_perfect_pitch : = (); -my @zok := (); -our @GUKGUK := (); -# state @widget_mark := (); -my %holy_seditives : = (); -my %bang := (); -our %GIGAZING := (); -# state %hex := (); -no warnings 'deprecated'; -my $holy_giveaways : = ''; -my $eee_yow := []; -our $TWOYYOYYOING_THUK_UGH := 1 == 1; -state $octothorn := 'Tinky Winky'; -my @holy_Taj_Mahal : = (); -my @touche := (); -our @PLAK_DAK_THUK_FRIT := (); -# state @hash_mark := (); -my %holy_priceless_collection_of_Etruscan_snoods : = (); -my %wham_eth := (); -our %THWUK := (); -# state %octalthorpe := (); -use warnings; -my $holy_sewer_pipe : = ''; -my $thunk := undef; -our $BLIT := time; -state $crunch := 'Laa Laa'; -my @glurpp := (); -my @holy_harem : = (); -our @FABADAP := (); -# state @square := (); -my %holy_pin_cushions : = (); -my %swoosh := (); -our %RRRRR := (); -# state %scratchmark := (); -EXPECT -Use of := for an empty attribute list is deprecated at - line 6. -Use of := for an empty attribute list is deprecated at - line 7. -Use of := for an empty attribute list is deprecated at - line 8. -Use of := for an empty attribute list is deprecated at - line 11. -Use of := for an empty attribute list is deprecated at - line 12. -Use of := for an empty attribute list is deprecated at - line 15. -Use of := for an empty attribute list is deprecated at - line 16. -Use of := for an empty attribute list is deprecated at - line 33. -Use of := for an empty attribute list is deprecated at - line 34. -Use of := for an empty attribute list is deprecated at - line 35. -Use of := for an empty attribute list is deprecated at - line 36. -Use of := for an empty attribute list is deprecated at - line 38. -Use of := for an empty attribute list is deprecated at - line 41. -Use of := for an empty attribute list is deprecated at - line 42. -######## -# toke.c use warnings 'syntax' ; my $a = "\o"; my $a = "\o{"; diff --git a/t/op/attrs.t b/t/op/attrs.t index 3013893..4e1a4c3 100644 --- a/t/op/attrs.t +++ b/t/op/attrs.t @@ -14,8 +14,6 @@ BEGIN { use warnings; -plan 92; - $SIG{__WARN__} = sub { die @_ }; sub eval_ok ($;$) { @@ -243,3 +241,58 @@ ok !defined(attributes::get(\PVBM)), $c=undef; eval 'sub t5 :Foo { }'; main::ok $c == \&{"t5"} && $c == $t5b && $c == $t5a; } + +my @tests = grep {/^[^#]/} split /\n/, <<'EOT'; +# This one is fine as an empty attribute list +my $holy_Einstein : = ''; +# This one is deprecated +my $krunch := 4; +our $FWISK_FWISK_FWIZZACH_FWACH_ZACHITTY_ZICH_SHAZZATZ_FWISK := ''; +state $thump := 'Trumpets'; +# Lather rinse repeat in my usual obsessive style +my @holy_perfect_pitch : = (); +my @zok := (); +our @GUKGUK := (); +# state @widget_mark := (); +my %holy_seditives : = (); +my %bang := (); +our %GIGAZING := (); +# state %hex := (); +my $holy_giveaways : = ''; +my $eee_yow := []; +our $TWOYYOYYOING_THUK_UGH := 1 == 1; +state $octothorn := 'Tinky Winky'; +my @holy_Taj_Mahal : = (); +my @touche := (); +our @PLAK_DAK_THUK_FRIT := (); +# state @hash_mark := (); +my %holy_priceless_collection_of_Etruscan_snoods : = (); +my %wham_eth := (); +our %THWUK := (); +# state %octalthorpe := (); +my $holy_sewer_pipe : = ''; +my $thunk := undef; +our $BLIT := time; +state $crunch := 'Laa Laa'; +my @glurpp := (); +my @holy_harem : = (); +our @FABADAP := (); +# state @square := (); +my %holy_pin_cushions : = (); +my %swoosh := (); +our %RRRRR := (); +# state %scratchmark := (); +EOT + +foreach my $test (@tests) { + use feature 'state'; + eval $test; + if ($test =~ /:=/) { + like $@, qr/Use of := for an empty attribute list is not allowed/, + "Parse error for q{$test}"; + } else { + is $@, '', "No error for q{$test}"; + } +} + +done_testing(); diff --git a/toke.c b/toke.c index 584aea0..d2868c2 100644 --- a/toke.c +++ b/toke.c @@ -5228,7 +5228,8 @@ Perl_yylex(pTHX) break; PL_bufptr = s; /* update in case we back off */ if (*s == '=') { - deprecate(":= for an empty attribute list"); + Perl_croak(aTHX_ + "Use of := for an empty attribute list is not allowed"); } goto grabattrs; case XATTRBLOCK: -- 2.7.4