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) }
use strict;
use warnings;
-use Test::More tests => 56;
+use Test::More tests => 58;
use Sub::Nary;
[ 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' ],
[ 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 ],
use strict;
use warnings;
-use Test::More tests => 40;
+use Test::More tests => 44;
use Sub::Nary;
[ 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 ],
[ 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' ],