Change 32743 by [EMAIL PROTECTED] on 2007/12/27 18:43:40
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.
Affected files ...
... //depot/perl/sv.c#1455 edit
... //depot/perl/t/op/gv.t#42 edit
Differences ...
==== //depot/perl/sv.c#1455 (text) ====
Index: perl/sv.c
--- perl/sv.c#1454~32740~ 2007-12-27 05:46:46.000000000 -0800
+++ perl/sv.c 2007-12-27 10:43:40.000000000 -0800
@@ -7665,7 +7665,8 @@
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);
==== //depot/perl/t/op/gv.t#42 (xtext) ====
Index: perl/t/op/gv.t
--- perl/t/op/gv.t#41~31940~ 2007-09-22 08:46:44.000000000 -0700
+++ perl/t/op/gv.t 2007-12-27 10:43:40.000000000 -0800
@@ -12,7 +12,7 @@
use warnings;
require './test.pl';
-plan( tests => 161 );
+plan( tests => 167 );
# type coersion on assignment
$foo = 'foo';
@@ -494,6 +494,30 @@
"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
End of Patch.