summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-09-05 12:05:16 +0200
committerYves Orton <demerphq@gmail.com>2022-09-08 07:55:45 +0200
commit077b44c7321d21b70dfdc26bc03d96b62d785cb8 (patch)
tree916b440d04c84facfbdb9dcdef2e19083dd849a7 /op.c
parent60d3cb45f882277cacea7440c4fdc3f3dc093403 (diff)
downloadperl-077b44c7321d21b70dfdc26bc03d96b62d785cb8.tar.gz
porting/diag.t - improved parsing a bit
The "multiline" logic of diag.t was getting confused by define statements that would define a symbol to call an error function but not end in ";", this would then slurp potentially many lines errorenously, potentially absorbing more than one message. The multi-line logic also would undef $listed_as and lose the diag_listed_as data in some circumstances. Fixing those issues revealed some interesting cases. To fix one of them I defined a new noop macro in perl.h to help: PERL_DIAG_WARN_SYNTAX(), which helps the diag.t parser identify messages without needing to be actually part of a specific message line. These macros are noops, they just return their argument, but they help hint to diag.t what is going on. Maybe in the future this can be reworked to be more generic, there are other similar cases that are not covered. Interestingly fixing this bug meant that at least one message that used to be erroneously picked up was no longer identified or tested. This was replaced with a PERL_DIAG_DIE_SYNTAX() wrapper.
Diffstat (limited to 'op.c')
-rw-r--r--op.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/op.c b/op.c
index e51c03cd9c..9de2326488 100644
--- a/op.c
+++ b/op.c
@@ -1877,20 +1877,26 @@ Perl_warn_elem_scalar_context(pTHX_ const OP *o, SV *name, bool is_hash, bool is
if (keypv) {
msg = is_slice ?
- "Scalar value @%" SVf "%c%s%c better written as $%" SVf "%c%s%c" :
- "%%%" SVf "%c%s%c in scalar context better written as $%" SVf "%c%s%c";
- /* diag_listed_as: %%s[%s] in scalar context better written as $%s[%s] */
- /* diag_listed_as: Scalar value @%s[%s] better written as $%s[%s] */
+ /* diag_listed_as: Scalar value @%s[%s] better written as $%s[%s] */
+ PERL_DIAG_WARN_SYNTAX(
+ "Scalar value @%" SVf "%c%s%c better written as $%" SVf "%c%s%c") :
+ /* diag_listed_as: %%s[%s] in scalar context better written as $%s[%s] */
+ PERL_DIAG_WARN_SYNTAX(
+ "%%%" SVf "%c%s%c in scalar context better written as $%" SVf "%c%s%c");
+
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), msg,
SVfARG(name), lbrack, keypv, rbrack,
SVfARG(name), lbrack, keypv, rbrack);
}
else {
msg = is_slice ?
- "Scalar value @%" SVf "%c%" SVf "%c better written as $%" SVf "%c%" SVf "%c" :
- "%%%" SVf "%c%" SVf "%c in scalar context better written as $%" SVf "%c%" SVf "%c";
- /* diag_listed_as: %%s[%s] in scalar context better written as $%s[%s] */
- /* diag_listed_as: Scalar value @%s[%s] better written as $%s[%s] */
+ /* diag_listed_as: Scalar value @%s[%s] better written as $%s[%s] */
+ PERL_DIAG_WARN_SYNTAX(
+ "Scalar value @%" SVf "%c%" SVf "%c better written as $%" SVf "%c%" SVf "%c") :
+ /* diag_listed_as: %%s[%s] in scalar context better written as $%s[%s] */
+ PERL_DIAG_WARN_SYNTAX(
+ "%%%" SVf "%c%" SVf "%c in scalar context better written as $%" SVf "%c%" SVf "%c");
+
Perl_warner(aTHX_ packWARN(WARN_SYNTAX), msg,
SVfARG(name), lbrack, SVfARG(keysv), rbrack,
SVfARG(name), lbrack, SVfARG(keysv), rbrack);