Skip to content

Commit 97a6211

Browse files
committed
Handle empty subroutine signatures in parse_subsignature() (Fixes #17689)
1 parent 4553a39 commit 97a6211

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ext/XS-APItest/t/subsignature.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ eval q{
1616
push @t, (subsignature @rest);
1717
push @t, (subsignature %rest);
1818
push @t, (subsignature $one = 1);
19+
20+
# these should all appear empty
21+
push @t, (subsignature );
22+
push @t, (subsignature);
23+
push @t, (subsignature #empty
24+
);
1925
};
2026
is $@, "";
2127
is_deeply \@t, [
@@ -24,6 +30,10 @@ is_deeply \@t, [
2430
['nextstate:6', 'multiparam:0..0:@:@rest=*'],
2531
['nextstate:7', 'multiparam:0..0:%:%rest=*'],
2632
['nextstate:8', 'multiparam:0..1:-:$one=0?'],
33+
34+
['nextstate:11', 'multiparam:0..0:-'],
35+
['nextstate:12', 'multiparam:0..0:-'],
36+
['nextstate:13', 'multiparam:0..0:-'],
2737
];
2838

2939
done_testing;

pod/perldelta.pod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ manager will later use a regex to expand these into links.
412412

413413
XXX
414414

415+
=item * C<parse_subsignature()> can now handle empty subroutine signatures
416+
417+
Previously, calling the C<parse_subsignature()> API function with an empty
418+
signature would cause a "Syntax error" failure, requiring code which calls it
419+
to detect the special case and take appropriate steps. This is now fixed,
420+
returning the same optree that the parser would yield for a regular empty
421+
signature during normal parse time.
422+
423+
[GH#17689]
424+
415425
=back
416426

417427
=head1 Known Problems

toke.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13922,6 +13922,18 @@ Perl_parse_subsignature(pTHX_ U32 flags)
1392213922
{
1392313923
if (flags)
1392413924
croak("Parsing code internal error (%s)", "parse_subsignature");
13925+
/* sub signatures might be empty, but perly.y can't cope with the
13926+
* ambiguity of an empty construction. We'll detect it manually and do
13927+
* something suitable in that case. */
13928+
lex_read_space(0);
13929+
if (lex_peek_unichar(0) == ')') {
13930+
/* pretend we saw an empty signature and do the same steps perly.y
13931+
* would have performed. */
13932+
subsignature_start();
13933+
OP *sigops = subsignature_finish();
13934+
CvSIGNATURE_on(PL_compcv);
13935+
return sigops;
13936+
}
1392513937
return parse_recdescent_for_op(GRAMSUBSIGNATURE, LEX_FAKEEOF_NONEXPR);
1392613938
}
1392713939

0 commit comments

Comments
 (0)