[perl #80630] Make eval"" return empty list for syntax errors
authorFather Chrysostomos <sprout@cpan.org>
Sat, 19 Nov 2011 19:13:24 +0000 (11:13 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 6 Dec 2011 16:42:05 +0000 (08:42 -0800)
Up till now, eval"" in list context was returning a list containing
undef for syntax errors and an empty list for run-time errors.

pp_ctl.c
t/comp/retainedlines.t
t/op/eval.t

index b38e8e6..953a749 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3649,7 +3649,7 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq, HV *hh)
                sv_setpvs(ERRSV, "Compilation error");
            }
        }
-       PUSHs(&PL_sv_undef);
+       if (gimme != G_ARRAY) PUSHs(&PL_sv_undef);
        PUTBACK;
        return FALSE;
     }
index 25687be..01557a6 100644 (file)
@@ -24,7 +24,7 @@ sub failed {
     return;
 }
 
-sub is {
+sub is($$$) {
     my ($got, $expect, $name) = @_;
     $test = $test + 1;
     if (defined $expect) {
index 78faa85..5cd7f4c 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan(tests => 121);
+plan(tests => 125);
 
 eval 'pass();';
 
@@ -25,6 +25,11 @@ like($@, qr/line 2/);
 print eval '$foo = /'; # this tests for a call through fatal()
 like($@, qr/Search/);
 
+is scalar(eval '++'), undef, 'eval syntax error in scalar context';
+is scalar(eval 'die'), undef, 'eval run-time error in scalar context';
+is +()=eval '++', 0, 'eval syntax error in list context';
+is +()=eval 'die', 0, 'eval run-time error in list context';
+
 is(eval '"ok 7\n";', "ok 7\n");
 
 $foo = 5;