diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-01-18 17:58:52 -0800 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2014-07-11 21:20:10 -0400 |
commit | c38e89e4398a95d797a67f51dca97f55b285b9f6 (patch) | |
tree | e74f97e92eebafb08901d9e712aa5928eb95c165 | |
parent | c8732df9f3d97961edd6849c3b2f64b6421a6ec3 (diff) | |
download | perl-c38e89e4398a95d797a67f51dca97f55b285b9f6.tar.gz |
[perl #119973] Treat initial { in format args as block
Commit 705fe0e5f8a inadvertently caused the hash-vs-block disambigua-
tion to apply at the beginning of a format argument line. This commit
restores the implicit ‘do’, but only when the opening brace is the
first token on that line, not embedded within an expression.
In other words, this now has a block as before:
format =
{ foo => "bar" }
.
but this still produces a hash (in 5.16 it was a block):
format =
+{ foo => "bar }
.
(cherry picked from commit f60e676307b23b6eadcbba505b4f71838fe212a2)
-rw-r--r-- | t/op/write.t | 21 | ||||
-rw-r--r-- | toke.c | 10 |
2 files changed, 30 insertions, 1 deletions
diff --git a/t/op/write.t b/t/op/write.t index 7dcf1e08f5..b126567a6b 100644 --- a/t/op/write.t +++ b/t/op/write.t @@ -64,7 +64,7 @@ my $bas_tests = 21; my $bug_tests = 8 + 3 * 3 * 5 * 2 * 3 + 2 + 66 + 4 + 2 + 3 + 96 + 11; # number of tests in section 4 -my $hmb_tests = 35; +my $hmb_tests = 37; my $tests = $bas_tests + $num_tests + $bug_tests + $hmb_tests; @@ -1091,6 +1091,25 @@ write HASH; close HASH or die "Could not close: $!"; is cat('Op_write.tmp'), "3\n", 'anonymous hashes'; +open(HASH2, '>Op_write.tmp') || die "Can't create Op_write.tmp"; +format HASH2 = +@<<< ++{foo=>"bar"} +. +write HASH2; +close HASH2 or die "Could not close: $!"; +is cat('Op_write.tmp'), "HASH\n", '+{...} is interpreted as anon hash'; + +# Anonymous hashes +open(BLOCK, '>Op_write.tmp') || die "Can't create Op_write.tmp"; +format BLOCK = +@<<< @<<< +{foo=>"bar"} # this is a block, not a hash! +. +write BLOCK; +close BLOCK or die "Could not close: $!"; +is cat('Op_write.tmp'), "foo bar\n", 'initial { is always BLOCK'; + # pragmata inside argument line open(STRICT, '>Op_write.tmp') || die "Can't create Op_write.tmp"; format STRICT = @@ -11221,6 +11221,16 @@ S_scan_formline(pTHX_ char *s) if (SvCUR(stuff)) { PL_expect = XSTATE; if (needargs) { + const char *s2 = s; + while (*s2 == '\r' || *s2 == ' ' || *s2 == '\t' || *s2 == '\f' + || *s2 == 013) + s2++; + if (*s2 == '{') { + start_force(PL_curforce); + PL_expect = XTERMBLOCK; + NEXTVAL_NEXTTOKE.ival = 0; + force_next(DO); + } start_force(PL_curforce); NEXTVAL_NEXTTOKE.ival = 0; force_next(FORMLBRACK); |