diff --git a/op.c b/op.c index 8d8574d3e950..ca3a2ff3d5fc 100644 --- a/op.c +++ b/op.c @@ -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)) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index f25f35af8ad8..71fd337ec88b 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -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 isn't one of +them. + =item Missing command in piped open (W pipe) You used the C or diff --git a/t/lib/croak/op b/t/lib/croak/op index d138e3187f55..cb0e8c8bc9dc 100644 --- a/t/lib/croak/op +++ b/t/lib/croak/op @@ -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.