From 231cbeb24ba077cbde643fc4d5178055c1464f5c Mon Sep 17 00:00:00 2001 From: Ruslan Zakirov Date: Mon, 8 Oct 2012 02:30:54 +0400 Subject: [PATCH] scalar(%h = (1,1,1,1)) should return 4, not 2 perldoc perlop says: a list assignment in scalar context returns the number of elements produced by the expression on the right hand side of the assignment Behaviour was changed as side effect of ca65944e8ff8fff6e36ea7476ba807be16cfe2a9 where goal was to fix return value in list context. --- ext/Hash-Util-FieldHash/t/11_hashassign.t | 4 ++-- pp_hot.c | 2 +- t/op/hashassign.t | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/Hash-Util-FieldHash/t/11_hashassign.t b/ext/Hash-Util-FieldHash/t/11_hashassign.t index e492fa2..d3e45d3 100644 --- a/ext/Hash-Util-FieldHash/t/11_hashassign.t +++ b/ext/Hash-Util-FieldHash/t/11_hashassign.t @@ -282,9 +282,9 @@ foreach my $chr (60, 200, 600, 6000, 60000) { fieldhash %h; is( (join ':', %h = (1) x 8), '1:1', 'hash assignment in list context removes duplicates' ); - is( scalar( %h = (1,2,1,3,1,4,1,5) ), 2, + is( scalar( %h = (1,2,1,3,1,4,1,5) ), 8, 'hash assignment in scalar context' ); - is( scalar( ($x,%h) = (0,1,2,1,3,1,4,1,5) ), 3, + is( scalar( ($x,%h) = (0,1,2,1,3,1,4,1,5) ), 9, 'scalar + hash assignment in scalar context' ); $ar = [ %h = (1,2,1,3,1,4,1,5) ]; is( $#$ar, 1, 'hash assignment in list context' ); diff --git a/pp_hot.c b/pp_hot.c index feba395..510d62b 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1234,7 +1234,7 @@ PP(pp_aassign) else if (gimme == G_SCALAR) { dTARGET; SP = firstrelem; - SETi(lastrelem - firstrelem + 1 - duplicates); + SETi(lastrelem - firstrelem + 1); } else { if (ary) diff --git a/t/op/hashassign.t b/t/op/hashassign.t index 37a7674..906e7ca 100644 --- a/t/op/hashassign.t +++ b/t/op/hashassign.t @@ -280,9 +280,9 @@ foreach my $chr (60, 200, 600, 6000, 60000) { 'hash assignment in list context removes duplicates' ); is( (join ':', %h = qw(a 1 a 2 b 3 c 4 d 5 d 6)), 'a:2:b:3:c:4:d:6', 'hash assignment in list context removes duplicates 2' ); - is( scalar( %h = (1,2,1,3,1,4,1,5) ), 2, + is( scalar( %h = (1,2,1,3,1,4,1,5) ), 8, 'hash assignment in scalar context' ); - is( scalar( ($x,%h) = (0,1,2,1,3,1,4,1,5) ), 3, + is( scalar( ($x,%h) = (0,1,2,1,3,1,4,1,5) ), 9, 'scalar + hash assignment in scalar context' ); $ar = [ %h = (1,2,1,3,1,4,1,5) ]; is( $#$ar, 1, 'hash assignment in list context' ); -- 2.7.4