From: Nicholas Clark Date: Thu, 27 Dec 2007 18:43:40 +0000 (+0000) Subject: You can't coerce a typeglob to a string. (Restore the error message - X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f257c956c5d42ce792dd5e0f3badf9851cef49c;p=p5sagit%2Fp5-mst-13.2.git You can't coerce a typeglob to a string. (Restore the error message - an assertion failure is not helpful). Test the 3 basic coercion error messages. p4raw-id: //depot/perl@32743 --- diff --git a/sv.c b/sv.c index 21ba31b..7b05674 100644 --- a/sv.c +++ b/sv.c @@ -7665,7 +7665,8 @@ Perl_sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags) else Perl_croak(aTHX_ "Can't coerce readonly %s to string", ref); } - if (SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM) + if ((SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM) + || isGV_with_GP(sv)) Perl_croak(aTHX_ "Can't coerce %s to string in %s", sv_reftype(sv,0), OP_NAME(PL_op)); s = sv_2pv_flags(sv, &len, flags); diff --git a/t/op/gv.t b/t/op/gv.t index 5b04f87..2fe0873 100755 --- a/t/op/gv.t +++ b/t/op/gv.t @@ -12,7 +12,7 @@ BEGIN { use warnings; require './test.pl'; -plan( tests => 161 ); +plan( tests => 167 ); # type coersion on assignment $foo = 'foo'; @@ -494,6 +494,30 @@ foreach my $value ([1,2,3], {1=>2}, *STDOUT{IO}, \&ok, *STDOUT{FORMAT}) { "Assigment works when glob created midway (bug 45607)"); 1' or die $@; } + +# For now these tests are here, but they would probably be better in a file for +# tests for croaks. (And in turn, that probably deserves to be in a different +# directory. Gerard Goossen has a point about the layout being unclear + +sub coerce_integer { + no warnings 'numeric'; + $_[0] |= 0; +} +sub coerce_number { + no warnings 'numeric'; + $_[0] += 0; +} +sub coerce_string { + $_[0] .= ''; +} + +foreach my $type (qw(integer number string)) { + my $prog = "coerce_$type(*STDERR)"; + is (scalar eval "$prog; 1", undef, "$prog failed..."); + like ($@, qr/Can't coerce GLOB to $type in/, + "with the correct error message"); +} + __END__ Perl Rules