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/perldelta.pod b/pod/perldelta.pod index bb49c79f7af4..2684d628c4a4 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -73,7 +73,25 @@ XXX For a release on a stable branch, this section aspires to be: If any exist, they are bugs, and we request that you submit a report. See L below. -[ List each incompatible change as a =head2 entry ] +=head2 C no longer allows an indirect object + +The C operator syntax now rejects indirect objects, in most +cases this would compile and even run, but wasn't documented and could +produce confusing results, for example: + + # note that sum hasn't been defined + sub sum_positive { + return sum grep $_ > 0, @_; + } + say for sum_positive(-1, 2, 3) + +produced: + + *main::sum + 2 + 3 + +[github #21716] =head1 Deprecations @@ -232,7 +250,11 @@ and New Warnings =item * -XXX L +L + +(F) While certain operators allow you to specify a filehandle or an +"indirect object" before the argument list, C isn't one of +them. =back 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.