Skip to content

Commit

Permalink
return doesn't allow an indirect object
Browse files Browse the repository at this point in the history
Since return isn't actually a function, I didn't think the "function"
part of the original message applied.

Fixes Perl#21716
  • Loading branch information
tonycoz committed Dec 18, 2023
1 parent e1e351e commit 12ea353
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -13654,6 +13654,13 @@ Perl_ck_return(pTHX_ OP *o)

PERL_ARGS_ASSERT_CK_RETURN;

if (o->op_flags & OPf_STACKED) {
kid = cUNOPx(OpSIBLING(cLISTOPo->op_first))->op_first;
if (kid->op_type != OP_SCOPE && kid->op_type != OP_LEAVE)
yyerror("Missing comma after first argument to return");
o->op_flags &= ~OPf_STACKED;
}

kid = OpSIBLING(cLISTOPo->op_first);
if (PL_compcv && CvLVALUE(PL_compcv)) {
for (; kid; kid = OpSIBLING(kid))
Expand Down
6 changes: 6 additions & 0 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -4003,6 +4003,12 @@ follow the C<\N>.
(F) While certain functions allow you to specify a filehandle or an
"indirect object" before the argument list, this ain't one of them.

=item Missing comma after first argument to return

(F) While certain operators allow you to specify a filehandle or an
"indirect object" before the argument list, C<return> isn't one of
them.

=item Missing command in piped open

(W pipe) You used the C<open(FH, "| command")> or
Expand Down
8 changes: 8 additions & 0 deletions t/lib/croak/op
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,11 @@ LOOP: {
}
EXPECT
Can't "last" out of a "finally" block at - line 4.
########
# NAME return HANDLE LIST isn't valid [github #21716]
sub xx {
return sum map { $_+1} 1 .. 5;
}
EXPECT
Missing comma after first argument to return at - line 2, near "5;"
Execution of - aborted due to compilation errors.

0 comments on commit 12ea353

Please sign in to comment.