From c38e89e4398a95d797a67f51dca97f55b285b9f6 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 18 Jan 2014 17:58:52 -0800 Subject: [perl #119973] Treat initial { in format args as block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- t/op/write.t | 21 ++++++++++++++++++++- toke.c | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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 = diff --git a/toke.c b/toke.c index 533f67f7d2..03b9b8cb76 100644 --- a/toke.c +++ b/toke.c @@ -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); -- cgit v1.2.1