Skip to content

Commit dc26b61

Browse files
author
Father Chrysostomos
committed
[perl #127976] Use yyerror for each $scalar error
yyerror queues the error, allowing for multiple error messages for syntax errors. So at compile time it is generally better than croak. It also provides more information about the location of the error, with things like ‘at EOF’ and ‘near such and such’. The hash functions each, values, and keys were using croak for the ‘Experimental forbidden’ message, unlike the array functions, which were already using yyerror. This commit changes the hash functions to use yyerror.
1 parent f861ba6 commit dc26b61

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

op.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11957,10 +11957,10 @@ Perl_ck_each(pTHX_ OP *o)
1195711957
/* we let ck_fun handle it */
1195811958
break;
1195911959
default:
11960-
Perl_croak_nocontext(
11960+
yyerror_pv(Perl_form(aTHX_
1196111961
"Experimental %s on scalar is now forbidden",
11962-
PL_op_desc[orig_type]);
11963-
break;
11962+
PL_op_desc[orig_type]), 0);
11963+
return o;
1196411964
}
1196511965
}
1196611966
return ck_fun(o);

t/op/smartkve.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ plan 'no_plan';
1515
my $empty;
1616

1717
sub set_errpat {
18-
$errpat = qr/Experimental $_[0] on scalar is now forbidden/;
18+
# Checking for a comma after the line number ensures that we are using
19+
# yyerror for the error, rather than croak. yyerror is preferable for
20+
# compile-time errors.
21+
$errpat =
22+
qr/Experimental $_[0] on scalar is now forbidden .* line 1,/;
1923
}
2024

2125
# Keys -- errors

0 commit comments

Comments
 (0)