This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Scalar keys assignment through lvalue subs
[perl5.git] / t / op / sub_lval.t
index a149a38..321f546 100644 (file)
@@ -3,7 +3,7 @@ BEGIN {
     @INC = '../lib';
     require './test.pl';
 }
-plan tests=>151;
+plan tests=>156;
 
 sub a : lvalue { my $a = 34; ${\(bless \$a)} }  # Return a temporary
 sub b : lvalue { ${\shift} }
@@ -450,6 +450,11 @@ while (/f/g) {
 }
 is("@p", "1 8");
 
+sub keeze : lvalue { keys %__ }
+%__ = ("a","b");
+keeze = 64;
+is scalar %__, '1/64', 'keys assignment through lvalue sub';
+
 # Bug 20001223.002: split thought that the list had only one element
 @ary = qw(4 5 6);
 sub lval1 : lvalue { $ary[0]; }
@@ -767,6 +772,7 @@ for my $sub (sub :lvalue {$_}, sub :lvalue {return $_}) {
 continue { $suffix = ' (explicit return)' }
 
 # autovivification
+$suffix = '';
 for my $sub (sub :lvalue {$_}, sub :lvalue {return $_}) {
     undef $_;
     &$sub()->[3] = 4;
@@ -785,3 +791,14 @@ for my $sub (sub :lvalue {$_}, sub :lvalue {return $_}) {
     is join('-',%$_), '4-5', '%{func()} autovivification'.$suffix;
 }
 continue { $suffix = ' (explicit return)' }
+
+# [perl #92406] [perl #92290] Returning a pad var in rvalue context
+$suffix = '';
+for my $sub (
+         sub :lvalue { my $x = 72; $x },
+         sub :lvalue { my $x = 72; return $x }
+) {
+    is scalar(&$sub), 72, "sub returning pad var in scalar context$suffix";
+    is +(&$sub)[0], 72, "sub returning pad var in list context$suffix";
+}
+continue { $suffix = ' (explicit return)' }