use warnings;
require './test.pl';
-plan( tests => 167 );
+plan( tests => 178 );
# type coersion on assignment
$foo = 'foo';
is (eval 'spritsits', "Value", "Constant has correct value");
is (ref \$::{spritsits}, 'GLOB', "Symbol table has full typeglob");
-my $result;
# Check that assignment to an existing typeglob works
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
- $result = *{"plunk"} = \&{"oonk"};
+ *{"plunk"} = [];
+ *{"plunk"} = \&{"oonk"};
is($w, '', "Should be no warning");
}
-is (ref \$result, 'GLOB',
- "Non void assignment should still return a typeglob");
-
is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
is (eval 'plunk', "Value", "Constant has correct value");
is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
{
my $w = '';
local $SIG{__WARN__} = sub { $w = $_[0] };
- $result = *{$gr} = \&{"oonk"};
+ *{$gr} = \&{"oonk"};
is($w, '', "Redefining a constant sub to another constant sub with the same underlying value should not warn (It's just re-exporting, and that was always legal)");
}
is (eval 'plunk', "Value", "Constant has correct value");
is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
+# Non-void context should defeat the optimisation, and will cause the original
+# to be promoted (what change 26482 intended)
+my $result;
+{
+ my $w = '';
+ local $SIG{__WARN__} = sub { $w = $_[0] };
+ $result = *{"awkkkkkk"} = \&{"oonk"};
+ is($w, '', "Should be no warning");
+}
+
+is (ref \$result, 'GLOB',
+ "Non void assignment should still return a typeglob");
+
+is (ref \$::{oonk}, 'GLOB', "This export does affect original");
+is (eval 'plunk', "Value", "Constant has correct value");
+is (ref \$::{plunk}, 'GLOB', "Symbol table has full typeglob");
+
+delete $::{oonk};
+$::{oonk} = \"Value";
+
+sub non_dangling {
+ my $w = '';
+ local $SIG{__WARN__} = sub { $w = $_[0] };
+ *{"zap"} = \&{"oonk"};
+ is($w, '', "Should be no warning");
+}
+
+non_dangling();
+is (ref $::{oonk}, 'SCALAR', "Export doesn't affect original");
+is (eval 'zap', "Value", "Constant has correct value");
+is (ref $::{zap}, 'SCALAR', "Exported target is also a PCS");
+
+sub dangling {
+ local $SIG{__WARN__} = sub { die $_[0] };
+ *{"biff"} = \&{"oonk"};
+}
+
+dangling();
+is (ref \$::{oonk}, 'GLOB', "This export does affect original");
+is (eval 'biff', "Value", "Constant has correct value");
+is (ref \$::{biff}, 'GLOB', "Symbol table has full typeglob");
+
{
use vars qw($glook $smek $foof);
# Check reference assignment isn't affected by the SV type (bug #38439)