From 1c2511e0acc5a19f9f52fb2be58a4e2750213e6f Mon Sep 17 00:00:00 2001 From: Aaron Crane Date: Mon, 13 Jul 2015 12:58:51 +0100 Subject: [PATCH] Make postfix dereferencing work without the postderef feature The feature still exists, for compatibility with code that tries to enable it, but it has no effect. The postderef_qq feature still exists, however. --- feature.h | 5 ++--- lib/feature.pm | 31 ++++++++++++++++++------------- pod/perldelta.pod | 9 ++++++--- pod/perlref.pod | 8 +++++--- regen/feature.pl | 29 +++++++++++++++++------------ t/lib/warnings/toke | 3 +-- t/op/postfixderef.t | 28 +--------------------------- toke.c | 5 ++--- 8 files changed, 52 insertions(+), 66 deletions(-) diff --git a/feature.h b/feature.h index dd98058..a527e06 100644 --- a/feature.h +++ b/feature.h @@ -78,9 +78,8 @@ #define FEATURE_POSTDEREF_IS_ENABLED \ ( \ - CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_523 \ - || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ - FEATURE_IS_ENABLED("postderef")) \ + CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ + FEATURE_IS_ENABLED("postderef") \ ) #define FEATURE_ARYBASE_IS_ENABLED \ diff --git a/lib/feature.pm b/lib/feature.pm index e2076ed..ec9fff7 100644 --- a/lib/feature.pm +++ b/lib/feature.pm @@ -29,7 +29,7 @@ our %feature_bundle = ( "5.10" => [qw(array_base say state switch)], "5.11" => [qw(array_base say state switch unicode_strings)], "5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)], - "5.23" => [qw(current_sub evalbytes fc postderef postderef_qq say state switch unicode_eval unicode_strings)], + "5.23" => [qw(current_sub evalbytes fc postderef_qq say state switch unicode_eval unicode_strings)], "all" => [qw(array_base bitwise current_sub evalbytes fc lexical_subs postderef postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)], "default" => [qw(array_base)], ); @@ -260,26 +260,31 @@ This feature is available from Perl 5.18 onwards. =head2 The 'postderef' and 'postderef_qq' features -The 'postderef' feature allows the use of L. For example, it will make the -following two statements equivalent: +The 'postderef_qq' feature extends the applicability of L so that postfix array +and scalar dereference are available in double-quotish interpolations. For +example, it makes the following two statements equivalent: - my @x = @{ $h->{a} }; - my @x = $h->{a}->@*; + my $s = "[@{ $h->{a} }]"; + my $s = "[$h->{a}->@*]"; -The 'postderef_qq' feature extends this, for array and scalar dereference, to -working inside of double-quotish interpolations. - -These features are available from Perl 5.20 onwards. In Perl 5.20 and 5.22, -they were classed as experimental, and Perl emitted a warning for their +This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it +was classed as experimental, and Perl emitted a warning for its usage, except when explicitly disabled: no warnings "experimental::postderef"; -As of Perl 5.24, use of these features no longer triggers a warning, though +As of Perl 5.24, use of this feature no longer triggers a warning, though the C warning category still exists (for compatibility with code that disables it). +The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable +postfix dereference syntax outside double-quotish interpolations. In those +versions, using it triggered the C warning in the +same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is +not only no longer experimental, but it is enabled for all Perl code, +regardless of what feature declarations are in scope. + =head2 The 'signatures' feature B: This feature is still experimental and the implementation may @@ -375,7 +380,7 @@ The following feature bundles are available: :5.24 say state switch unicode_strings unicode_eval evalbytes current_sub fc - postderef postderef_qq + postderef_qq The C<:default> bundle represents the feature set that is enabled before any C or C declaration. diff --git a/pod/perldelta.pod b/pod/perldelta.pod index ce8768b..ae26fbb 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -52,9 +52,12 @@ you could use the C pragma. =head2 Postfix dereferencing is no longer experimental -Using the C and C features no longer emits a warning. -Existing code that disables that warning category will continue to work. The -C<5.24> feature bundle now includes those features. +Using the C and C features no longer emits a +warning. Existing code that disables the C warning +category that they previously used will continue to work. The C +feature has no effect; all Perl code can use postfix dereferencing, +regardless of what feature declarations are in scope. The C<5.24> feature +bundle now includes the C feature. =head1 Security diff --git a/pod/perlref.pod b/pod/perlref.pod index 8956be5..e570b72 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -758,7 +758,9 @@ For example: $r = [ 1, [ 2, 3 ], 4 ]; $r->[1]->@*; # equivalent to @{ $r->[1] } -This syntax must be enabled with C. +In Perl 5.20 and 5.22, this syntax must be enabled with C. As of Perl 5.24, no feature declarations are required to make +it available. Postfix dereference should work in all circumstances where block (circumfix) dereference worked, and should be entirely equivalent. This @@ -781,7 +783,7 @@ Glob elements can be extracted through the postfix dereferencing feature: Postfix array and scalar dereferencing I be used in interpolating strings (double quotes or the C operator), but only if the -additional C feature is enabled. +C feature is enabled. =head2 Postfix Reference Slicing @@ -800,7 +802,7 @@ Slices">, also behaves as expected: As with postfix array, postfix value slice dereferencing I be used in interpolating strings (double quotes or the C operator), but only -if the additional C L is enabled. +if the C L is enabled. =head1 Assigning to References diff --git a/regen/feature.pl b/regen/feature.pl index a7b6e5d..85ab2b0 100755 --- a/regen/feature.pl +++ b/regen/feature.pl @@ -60,7 +60,7 @@ my %feature_bundle = ( "5.21" => [qw(say state switch unicode_strings unicode_eval evalbytes current_sub fc)], "5.23" => [qw(say state switch unicode_strings unicode_eval - evalbytes current_sub fc postderef postderef_qq)], + evalbytes current_sub fc postderef_qq)], ); # not actually used currently @@ -575,26 +575,31 @@ This feature is available from Perl 5.18 onwards. =head2 The 'postderef' and 'postderef_qq' features -The 'postderef' feature allows the use of L. For example, it will make the -following two statements equivalent: +The 'postderef_qq' feature extends the applicability of L so that postfix array +and scalar dereference are available in double-quotish interpolations. For +example, it makes the following two statements equivalent: - my @x = @{ $h->{a} }; - my @x = $h->{a}->@*; + my $s = "[@{ $h->{a} }]"; + my $s = "[$h->{a}->@*]"; -The 'postderef_qq' feature extends this, for array and scalar dereference, to -working inside of double-quotish interpolations. - -These features are available from Perl 5.20 onwards. In Perl 5.20 and 5.22, -they were classed as experimental, and Perl emitted a warning for their +This feature is available from Perl 5.20 onwards. In Perl 5.20 and 5.22, it +was classed as experimental, and Perl emitted a warning for its usage, except when explicitly disabled: no warnings "experimental::postderef"; -As of Perl 5.24, use of these features no longer triggers a warning, though +As of Perl 5.24, use of this feature no longer triggers a warning, though the C warning category still exists (for compatibility with code that disables it). +The 'postderef' feature was used in Perl 5.20 and Perl 5.22 to enable +postfix dereference syntax outside double-quotish interpolations. In those +versions, using it triggered the C warning in the +same way as the 'postderef_qq' feature did. As of Perl 5.24, this syntax is +not only no longer experimental, but it is enabled for all Perl code, +regardless of what feature declarations are in scope. + =head2 The 'signatures' feature B: This feature is still experimental and the implementation may diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index d65467c..ad0e74b 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -1040,10 +1040,9 @@ EXPECT Useless use of \E at - line 3. ######## # toke.c -use feature 'postderef', 'postderef_qq'; +use feature 'postderef_qq'; (\$_)->$*; "$_->$*"; -no warnings 'experimental::postderef'; (\$_)->$*; "$_->$*"; EXPECT diff --git a/t/op/postfixderef.t b/t/op/postfixderef.t index 920bc2d..77988bf 100644 --- a/t/op/postfixderef.t +++ b/t/op/postfixderef.t @@ -16,33 +16,7 @@ BEGIN { use strict qw(refs subs); -plan(125); - -{ - no warnings qw 'deprecated syntax'; - eval '[]->$*'; - like $@, qr/Can't call method/, '->$* outside of feature scope'; - eval '[]->@*'; - like $@, qr/syntax error/, '->@* outside of feature scope'; - eval '[]->@[1]'; - like $@, qr/syntax error/, '->@[ outside of feature scope'; - eval '[]->@{1}'; - like $@, qr/syntax error/, '->@{ outside of feature scope'; - eval '[]->%*'; - like $@, qr/syntax error/, '->%* outside of feature scope'; - eval '[]->%[1]'; - like $@, qr/syntax error/, '->%[ outside of feature scope'; - eval '[]->%{1}'; - like $@, qr/syntax error/, '->%{ outside of feature scope'; - eval '[]->&*'; - like $@, qr/syntax error/, '->&* outside of feature scope'; - eval '[]->**'; - like $@, qr/syntax error/, '->** outside of feature scope'; - eval '[]->*{'; - like $@, qr/syntax error/, '->*{ outside of feature scope'; -} - -use feature 'postderef'; +plan(115); { no strict 'refs'; diff --git a/toke.c b/toke.c index 763baa5..29ebbbf 100644 --- a/toke.c +++ b/toke.c @@ -5133,12 +5133,11 @@ Perl_yylex(pTHX) else if (*s == '>') { s++; s = skipspace(s); - if (FEATURE_POSTDEREF_IS_ENABLED && ( - ((*s == '$' || *s == '&') && s[1] == '*') + if (((*s == '$' || *s == '&') && s[1] == '*') ||(*s == '$' && s[1] == '#' && s[2] == '*') ||((*s == '@' || *s == '%') && strchr("*[{", s[1])) ||(*s == '*' && (s[1] == '*' || s[1] == '{')) - )) + ) { PL_expect = XPOSTDEREF; TOKEN(ARROW); -- 1.8.3.1