Skip to content

Commit

Permalink
‘%s found where op expected’ under fatal warnings
Browse files Browse the repository at this point in the history
This is related to ticket #123195.

This code:

use warnings FATAL => 'all';
use strict;
$foo;
myfunc 1,2,3
__END__

was giving this:

Global symbol "$foo" requires explicit package name (did you forget to declare "my $foo"?) at - line 3.
	(Do you need to predeclare myfunc?)
syntax error at - line 4, near "myfunc 1"
Execution of - aborted due to compilation errors.

How can we have ‘Do you need to predeclare myfunc?’ without any prior
mention of myfunc in the diagnostics?  Fatal warnings were modified in
594b6fa to queue compile-time warning and emit them as part of the
error message.  But the logic was not quite right for yywarn, which is
used for ‘foo found where operator expected’.  The warning was just
disappearing outside of an eval.  qerror was treating PL_in_eval as
a boolean, so we need to clear the flag we have just set, before
we call it.
  • Loading branch information
Father Chrysostomos committed Nov 13, 2014
1 parent 13adb05 commit b255a11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions t/lib/croak/toke
@@ -1,4 +1,24 @@
__END__
# NAME foo found where operator expected
myfunc 1,2,3
EXPECT
Number found where operator expected at - line 1, near "myfunc 1"
(Do you need to predeclare myfunc?)
syntax error at - line 1, near "myfunc 1"
Execution of - aborted due to compilation errors.
########
# NAME foo found where operator expected (after strict error, w/fatal warnings)
use warnings FATAL => 'all';
use strict;
$foo;
myfunc 1,2,3
EXPECT
Global symbol "$foo" requires explicit package name (did you forget to declare "my $foo"?) at - line 3.
Number found where operator expected at - line 4, near "myfunc 1"
(Do you need to predeclare myfunc?)
syntax error at - line 4, near "myfunc 1"
Execution of - aborted due to compilation errors.
########
# NAME Unterminated here-doc in string eval
eval "<<foo"; die $@
EXPECT
Expand Down
2 changes: 1 addition & 1 deletion toke.c
Expand Up @@ -10557,7 +10557,6 @@ S_yywarn(pTHX_ const char *const s, U32 flags)

PL_in_eval |= EVAL_WARNONLY;
yyerror_pv(s, flags);
PL_in_eval &= ~EVAL_WARNONLY;
return 0;
}

Expand Down Expand Up @@ -10661,6 +10660,7 @@ Perl_yyerror_pvn(pTHX_ const char *const s, STRLEN len, U32 flags)
PL_multi_end = 0;
}
if (PL_in_eval & EVAL_WARNONLY) {
PL_in_eval &= ~EVAL_WARNONLY;
Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "%"SVf, SVfARG(msg));
}
else
Expand Down

0 comments on commit b255a11

Please sign in to comment.