This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make warn treat $@=3 and $@="3" the same
authorFather Chrysostomos <sprout@cpan.org>
Thu, 7 Jun 2012 06:19:47 +0000 (23:19 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 7 Jun 2012 15:18:55 +0000 (08:18 -0700)
If we get this:

$ ./perl -Ilib -e '$@ = "3"; warn'
3 ...caught at -e line 1.

then we shouldn’t get this:

$ ./perl -Ilib -e '$@ = 3; warn'
Warning: something's wrong at -e line 1.

as the two scalars hold the same value.

pp_sys.c
t/op/warn.t

index 994bd6c..79ef266 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -453,7 +453,7 @@ PP(pp_warn)
        }
        else exsv = ERRSV;
       }
-      else if (SvPOKp(ERRSV) && SvCUR(ERRSV)) {
+      else if (SvPOKp(ERRSV) ? SvCUR(ERRSV) : SvNIOKp(ERRSV)) {
        exsv = sv_newmortal();
        sv_setsv_nomg(exsv, ERRSV);
        sv_catpvs(exsv, "\t...caught");
index a0a072e..71de5e2 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan 28;
+plan 30;
 
 my @warnings;
 my $wa = []; my $ea = [];
@@ -186,4 +186,10 @@ is @warnings, 1;
 object_ok $warnings[0], 'o',
   'warn $tie_returning_object_that_stringifes_emptily';
 
+@warnings = ();
+eval "#line 42 Cholmondeley\n \$\@ = '3'; warn";
+eval "#line 42 Cholmondeley\n \$\@ = 3; warn";
+is @warnings, 2;
+is $warnings[1], $warnings[0], 'warn treats $@=3 and $@="3" the same way';
+
 1;