From: Vincent Pit Date: Tue, 5 Aug 2008 14:02:08 +0000 (+0200) Subject: Get the good count in aassign. Fixes successive arrays assignments and goatse operato... X-Git-Tag: v0.02~2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=50a68c0adea943d70170c8e5387d703a045f90e7;p=perl%2Fmodules%2FSub-Nary.git Get the good count in aassign. Fixes successive arrays assignments and goatse operator. Add tests for that and more --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 707a2e6..a6b97e0 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -441,7 +441,17 @@ sub pp_rv2av { return (name($op) eq 'const') ? $self->expect_any($op) : 'list'; } -sub pp_aassign { $_[0]->expect_any($_[1]->first) } +sub pp_aassign { + my ($self, $op) = @_; + + $op = $op->first; + + # Can't assign to return + my ($p, $r) = $self->expect_list($op->sibling); + return $p => 0 if not exists $p->{list}; + + $self->expect_any($op); +} sub pp_leaveloop { $_[0]->expect_return($_[1]->first->sibling) } diff --git a/t/20-return.t b/t/20-return.t index 191a386..fc63f95 100644 --- a/t/20-return.t +++ b/t/20-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 56; +use Test::More tests => 58; use Sub::Nary; @@ -31,6 +31,7 @@ my @tests = ( [ sub { return $a[0] }, 1 ], [ sub { return @a[1, 2] }, 2 ], [ sub { return @a[2 .. 4] }, 3 ], + [ sub { return @a[1, 4 .. 7, 2] }, 6 ], [ sub { return @a[do{ 1 .. 5 }] }, 5 ], [ sub { return @a[do{ 1 .. $x }] }, 'list' ], @@ -46,13 +47,14 @@ my @tests = ( [ sub { return $x, @a }, 'list' ], [ sub { return %h, $y }, 'list' ], - [ sub { return 1 .. 3 }, 3 ], + [ sub { return 2 .. 4 }, 3 ], [ sub { return $x .. 3 }, 'list' ], [ sub { return 1 .. $x }, 'list' ], [ sub { return '2foo' .. 4 }, 3 ], [ sub { my @a = (7, 8); return @a .. 4 }, 'list' ], [ sub { return do { return 1, 2 } .. 3 }, 2 ], [ sub { return 1 .. do { return 2, 3 } }, 2 ], + [ sub { my @a = return 6, $x }, 2 ], [ sub { for (1, 2, 3) { return } }, 0 ], [ sub { for (1, 2, 3) { } return 1, 2; }, 2 ], diff --git a/t/21-list.t b/t/21-list.t index 3acf659..4dc492a 100644 --- a/t/21-list.t +++ b/t/21-list.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 44; use Sub::Nary; @@ -25,10 +25,11 @@ my @tests = ( [ sub { $x }, 1 ], [ sub { $x, $y }, 2 ], - [ sub { @a }, 'list' ], - [ sub { $a[0] }, 1 ], - [ sub { @a[1, 2] }, 2 ], - [ sub { @a[2 .. 4] }, 3 ], + [ sub { @a }, 'list' ], + [ sub { $a[0] }, 1 ], + [ sub { @a[1, 2] }, 2 ], + [ sub { @a[2 .. 4] }, 3 ], + [ sub { @a[1, 4 .. 7, 2] }, 6 ], [ sub { %h }, 'list' ], [ sub { $h{a} }, 1 ], @@ -40,12 +41,15 @@ my @tests = ( [ sub { $x, @a }, 'list' ], [ sub { %h, $y }, 'list' ], - [ sub { 1 .. 3 }, 3 ], - [ sub { $x .. 3 }, 'list' ], - [ sub { 1 .. $x }, 'list' ], - [ sub { '2foo' .. 4 }, 3 ], - [ sub { my @a = (7, 8); @a .. 4 }, 'list' ], - [ sub { my @a = (1 .. 4) }, 4 ], + [ sub { 2 .. 4 }, 3 ], + [ sub { $x .. 3 }, 'list' ], + [ sub { 1 .. $x }, 'list' ], + [ sub { '2foo' .. 4 }, 3 ], + [ sub { my @a = (7, 8); @a .. 4 }, 'list' ], + [ sub { my @a = (2 .. 5) }, 4 ], + [ sub { my @b; my @a = @b = (2 .. 5) }, 4 ], + [ sub { my @a =()= (2 .. 5) }, 0 ], + [ sub { my $x =()= (2 .. 5) }, 1 ], [ sub { "banana" =~ /(a)/g }, 'list' ],