summaryrefslogtreecommitdiff
path: root/t/base
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-10-28 16:52:18 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-10-28 17:46:59 -0700
commite660c409f22c1a7f1be06f3ef5168a7a09a5835a (patch)
tree53e98177dd87a5996024c8039f9c4b057677eef6 /t/base
parent00e40766a52e90fea69000c44dbc74c62133f696 (diff)
downloadperl-e660c409f22c1a7f1be06f3ef5168a7a09a5835a.tar.gz
[perl #122782] map{no strict;...} etc.
After the lexer (toke.c) has decided in the case of ‘map{’ or ‘print{’ that it has a block, not a hash constructor, it has then preceded to treat the contents as an expression. Since it is the parser (perly.y) that ultimately decides whether it is an expression or statement, most of the time things just work. But in those cases where the lexer behaves differently whether it is expect- ing a statement or expression, it usually just does the wrong thing. Most notable is map {no strict;...}, which dies with ‘"no" not allowed in expression’. See the RT ticket for more examples of the term/statement discrepancies. This commit changes it to expect a statement most of the time. These changes also apply to the contents of ${...}, which has always fol- lowed the same rules. Two cases where it used simply to dwim that would break with a statement expectation are special-cased, to pre- serve backward-compatibility as much as possible. See the comments added to toke. We already have an exception for ‘sub’ in the case of ${sub{...}}, which is not treated as $sub{...} as happens with other barewords, so this is consistent with that.
Diffstat (limited to 't/base')
-rw-r--r--t/base/lex.t32
1 files changed, 31 insertions, 1 deletions
diff --git a/t/base/lex.t b/t/base/lex.t
index 7604ee1e7d..a9072ac3f4 100644
--- a/t/base/lex.t
+++ b/t/base/lex.t
@@ -1,6 +1,6 @@
#!./perl
-print "1..93\n";
+print "1..101\n";
$x = 'x';
@@ -444,3 +444,33 @@ print "not " unless
(eval '${Function_with_side_effects,\$_}' || $@)
eq "sidekick function called";
print "ok $test - \${...} where {...} looks like hash\n"; $test++;
+
+@_ = map{BEGIN {$_122782 = 'tst2'}; "rhu$_"} 'barb2';
+print "not " unless "@_" eq 'rhubarb2';
+print "ok $test - map{BEGIN...\n"; $test++;
+print "not " unless $_122782 eq 'tst2';
+print "ok $test - map{BEGIN...\n"; $test++;
+${
+=pod
+blah blah blah
+=cut
+\$_ } = 42;
+print "not "unless $_ == 42;
+print "ok $test - \${ <newline> =pod\n"; $test++;
+@_ = map{
+=pod
+blah blah blah
+=cut
+$_+1 } 1;
+print "not "unless "@_" eq 2;
+print "ok $test - map{ <newline> =pod\n"; $test++;
+eval { ${...}++ };
+print "not " unless $@ =~ /^Unimplemented at /;
+print "ok $test - \${...} (literal triple-dot)\n"; $test++;
+eval { () = map{...} @_ };
+print "not " unless $@ =~ /^Unimplemented at /;
+print "ok $test - map{...} (literal triple-dot)\n"; $test++;
+print "not " unless &{sub :lvalue { "a" }} eq "a";
+print "ok $test - &{sub :lvalue...}\n"; $test++;
+print "not " unless ref+(map{sub :lvalue { "a" }} 1)[0] eq "CODE";
+print "ok $test - map{sub :lvalue...}\n"; $test++;