Make my $pi := 4; a syntax error.
authorNicholas Clark <nick@ccl4.org>
Fri, 26 Nov 2010 15:53:56 +0000 (15:53 +0000)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 28 Nov 2010 21:17:06 +0000 (13:17 -0800)
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
pod/perldelta.pod
pod/perldiag.pod
t/lib/warnings/toke
t/op/attrs.t
toke.c

index 3ae14e9..38ce876 100644 (file)
@@ -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;
 >>>>
index d85f1ba..2a35cc4 100644 (file)
@@ -67,12 +67,20 @@ L</Selected Bug Fixes> 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<my $pi := 4;> was exactly equivalent to C<my $pi : = 4;>,
+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
 
index c186919..7250057 100644 (file)
@@ -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<my $x := 42> currently
-parses correctly in perl, being equivalent to C<my $x : = 42>
-(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<my $x := 42> used to parse as equivalent to
+C<my $x : = 42> (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
 
index 7096620..5468ef0 100644 (file)
@@ -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{";
index 3013893..4e1a4c3 100644 (file)
@@ -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 (file)
--- 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: