Skip to content

Commit

Permalink
for my ($foo,,, $bar) { ... } should parse as ($foo, $bar)
Browse files Browse the repository at this point in the history
Multiple commas between the lexicals in the list shouldn't change the
parsing.
  • Loading branch information
nwc10 committed Sep 16, 2021
1 parent a4fa3f9 commit e091bd9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
4 changes: 2 additions & 2 deletions perly.act
Expand Up @@ -2070,7 +2070,7 @@ case 2:

case 276:
#line 1387 "perly.y"
{ parser->in_my = 0; (yyval.opval) = (ps[-1].val.opval); }
{ (yyval.opval) = (ps[-1].val.opval); }

break;

Expand Down Expand Up @@ -2183,6 +2183,6 @@ case 2:


/* Generated from:
* e87297a1b718c1eb135698aef6d0fe1da0c008db89e13c13a2f746afc9dba3e3 perly.y
* 15f94e78bed944fe5a2da8ead4096a620ad573562953c479348c65e9eaa51629 perly.y
* acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl
* ex: set ro: */
2 changes: 1 addition & 1 deletion perly.h
Expand Up @@ -224,6 +224,6 @@ int yyparse (void);


/* Generated from:
* e87297a1b718c1eb135698aef6d0fe1da0c008db89e13c13a2f746afc9dba3e3 perly.y
* 15f94e78bed944fe5a2da8ead4096a620ad573562953c479348c65e9eaa51629 perly.y
* acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl
* ex: set ro: */
2 changes: 1 addition & 1 deletion perly.tab
Expand Up @@ -1448,6 +1448,6 @@ static const toketypes yy_type_tab[] =
};

/* Generated from:
* e87297a1b718c1eb135698aef6d0fe1da0c008db89e13c13a2f746afc9dba3e3 perly.y
* 15f94e78bed944fe5a2da8ead4096a620ad573562953c479348c65e9eaa51629 perly.y
* acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl
* ex: set ro: */
2 changes: 1 addition & 1 deletion perly.y
Expand Up @@ -1384,7 +1384,7 @@ my_scalar: scalar

/* A list of scalars for "for my ($foo, $bar) (@baz)" */
list_of_scalars: list_of_scalars[list] PERLY_COMMA
{ parser->in_my = 0; $$ = $list; }
{ $$ = $list; }
| list_of_scalars[list] PERLY_COMMA scalar
{
$$ = op_append_elem(OP_LIST, $list, $scalar);
Expand Down
42 changes: 41 additions & 1 deletion t/op/for-many.t
Expand Up @@ -8,6 +8,7 @@ BEGIN {

use strict;
use warnings;
use utf8;

my @have;

Expand Down Expand Up @@ -118,7 +119,7 @@ is("@have", 'A B C D E F', 'one-at-a-time');

# Arrays have an optimised case in pp_iter:
{
no strict;
no strict 'vars';

@array = split ' ', 'Dogs have owners, cats have staff.';

Expand Down Expand Up @@ -460,4 +461,43 @@ is($redo, 3, 'redo reached thrice');
is($next, 2, 'next reached twice');
is($continue, 'xx', 'continue reached twice');

{
no strict 'vars';
# Important that this is a package variable, so that we test that the parser
# ends the scope of the my at the ')' and generates the correct ops to read
# from the symbol table, not the pad.

@Lamini = qw(alpaca guanaco llama vicuña);

@have = ();
for my ($domestic, $wild) (@Lamini) {
push @have, "$domestic;$wild";
}
is("@have", 'alpaca;guanaco llama;vicuña', 'comma test 0');

@have = ();
for my ($domestic, $wild,) (@Lamini) {
push @have, "$domestic;$wild";
}
is("@have", 'alpaca;guanaco llama;vicuña', 'comma test 1');

@have = ();
for my ($domestic,, $wild) (@Lamini) {
push @have, "$domestic;$wild";
}
is("@have", 'alpaca;guanaco llama;vicuña', 'comma test 2');

@have = ();
for my ($domestic,, $wild,) (@Lamini) {
push @have, "$domestic;$wild";
}
is("@have", 'alpaca;guanaco llama;vicuña', 'comma test 3');

@have = ();
for my ($domestic,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, $wild) (@Lamini) {
push @have, "$domestic;$wild";
}
is("@have", 'alpaca;guanaco llama;vicuña', 'comma test 42');
}

done_testing();

0 comments on commit e091bd9

Please sign in to comment.