8 sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
9 sub b : lvalue { ${\shift} }
11 my $out = a(b()); # Check that temporaries are allowed.
12 is(ref $out, 'main'); # Not reached if error.
14 my @out = grep /main/, a(b()); # Check that temporaries are allowed.
15 cmp_ok(scalar @out, '==', 1); # Not reached if error.
19 # Check that we can return localized values from subroutines:
21 sub in : lvalue { $in = shift; }
22 sub neg : lvalue { #(num_str) return num_str
32 sub get_lex : lvalue { $in }
33 sub get_st : lvalue { $blah }
34 sub id : lvalue { ${\shift} }
35 sub id1 : lvalue { $_[0] }
36 sub inc : lvalue { ${\++$_[0]} }
43 cmp_ok($blah, '==', 7);
51 cmp_ok($blah, '==', 8);
59 cmp_ok($blah, '==', 10);
63 cmp_ok($in, '==', 10);
67 cmp_ok($blah, '==', 11);
71 cmp_ok($in, '==', 11);
75 cmp_ok($blah, '==', 20);
79 cmp_ok($in, '==', 20);
83 cmp_ok($blah, '==', 21);
87 cmp_ok($in, '==', 21);
91 cmp_ok($blah, '==', 22);
95 cmp_ok($in, '==', 22);
99 cmp_ok($blah, '==', 23);
103 cmp_ok($in, '==', 23);
105 ++inc(id1(id(get_st)));
107 cmp_ok($blah, '==', 25);
109 ++inc(id1(id(get_lex)));
111 cmp_ok($in, '==', 25);
115 $#c = 3; # These slots are not fillable.
117 # Explanation: empty slots contain &sv_undef.
119 =for disabled constructs
127 eval <<'EOE' or $_ = $@;
128 ($x, a3, $y, b2, $z, c4, $t) = (34 .. 78);
132 #@out = ($x, a3, $y, b2, $z, c4, $t);
133 #@in = (34 .. 41, (undef) x 4, 46);
134 #print "# '@out' ne '@in'\nnot " unless "@out" eq "@in";
136 like($_, qr/Can\'t return an uninitialized value from lvalue subroutine/);
144 sub a::var : lvalue { $var }
148 cmp_ok($var, '==', 45);
151 $o = bless \$oo, "a";
155 cmp_ok($var, '==', 47);
157 sub o : lvalue { $o }
161 cmp_ok($var, '==', 49);
163 sub nolv () { $x0, $x1 } # Not lvalue
167 eval <<'EOE' or $_ = $@;
172 like($_, qr/Can\'t modify non-lvalue subroutine call in scalar assignment/);
176 eval <<'EOE' or $_ = $@;
181 like($_, qr/Can\'t modify non-lvalue subroutine call in scalar assignment/);
185 eval <<'EOE' or $_ = $@;
190 like($_, qr/Can\'t modify non-lvalue subroutine call in scalar assignment/);
192 $x0 = $x1 = $_ = undef;
195 eval <<'EOE' or $_ = $@;
196 $nolv->() = (2,3) if $_;
200 ok(!defined $_) or diag "'$_', '$x0', '$x1'";
202 $x0 = $x1 = $_ = undef;
205 eval <<'EOE' or $_ = $@;
210 like($_, qr/Can\'t modify non-lvalue subroutine call/)
211 or diag "'$_', '$x0', '$x1'";
214 sub rlv0 : lvalue { return }
217 eval <<'EOE' or $_ = $@;
222 like($_, qr/Can't return undef from lvalue subroutine/);
225 eval <<'EOE' or $_ = $@;
230 like($_, qr/Can't return undef from lvalue subroutine/,
231 'explicit return of nothing in scalar context');
234 eval <<'EOE' or $_ = $@;
239 ok(!defined $_) or diag $_;
242 eval <<'EOE' or $_ = $@;
247 ok(!defined $_, 'explicit return of nothing in list context') or diag $_;
250 (lv0($a,$b)) = (3,4);
251 is +($a//'undef') . ($b//'undef'), 'undefundef',
252 'list assignment to empty lvalue sub';
255 sub lv1u :lvalue { undef }
256 sub rlv1u :lvalue { undef }
259 eval <<'EOE' or $_ = $@;
264 like($_, qr/Can't return undef from lvalue subroutine/);
267 eval <<'EOE' or $_ = $@;
272 like($_, qr/Can't return undef from lvalue subroutine/,
273 'explicitly returning undef in scalar context');
276 eval <<'EOE' or $_ = $@;
281 ok(!defined, 'implicitly returning undef in list context');
284 eval <<'EOE' or $_ = $@;
289 ok(!defined, 'explicitly returning undef in list context');
294 eval <<'EOE' or $_ = $@;
295 sub lv1t : lvalue { index $x, 2 }
300 like($_, qr/Can\'t return a temporary from lvalue subroutine/);
303 eval <<'EOE' or $_ = $@;
304 sub rlv1t : lvalue { index $x, 2 }
309 like($_, qr/Can\'t return a temporary from lvalue subroutine/,
310 'returning a PADTMP explicitly');
313 eval <<'EOE' or $_ = $@;
318 like($_, qr/Can\'t return a temporary from lvalue subroutine/,
319 'returning a PADTMP explicitly (list context)');
321 # These next two tests are not necessarily normative. But this way we will
322 # know if this discrepancy changes.
325 eval <<'EOE' or $_ = $@;
326 sub scalarray : lvalue { @a || $b }
332 like($_, qr/Can\'t return a temporary from lvalue subroutine/,
333 'returning a scalar-context array via ||');
336 eval <<'EOE' or $_ = $@;
337 use warnings "FATAL" => "all";
338 sub myscalarray : lvalue { my @a = 1; @a || $b }
339 (myscalarray) = (2,3);
343 like($_, qr/Useless assignment to a temporary/,
344 'returning a scalar-context lexical array via ||');
347 sub lv2t : lvalue { shift }
352 sub xxx () { $xxx } # Not lvalue
355 eval <<'EOE' or $_ = $@;
356 sub lv1tmp : lvalue { xxx } # is it a TEMP?
361 like($_, qr/Can\'t modify non-lvalue subroutine call at /);
364 eval <<'EOE' or $_ = $@;
369 like($_, qr/Can\'t modify non-lvalue subroutine call at /);
371 sub yyy () { 'yyy' } # Const, not lvalue
374 eval <<'EOE' or $_ = $@;
375 sub lv1tmpr : lvalue { yyy } # is it read-only?
380 like($_, qr/Can\'t return a readonly value from lvalue subroutine at/);
383 eval <<'EOE' or $_ = $@;
388 like($_, qr/Can\'t return a readonly value from lvalue subroutine/);
390 sub lva : lvalue {@a}
395 eval <<'EOE' or $_ = $@;
400 is("'@a' $_", "'2 3' ");
406 eval <<'EOE' or $_ = $@;
411 is("'@a' $_", "'2 3' ");
413 is lva->${\sub { return $_[0] }}, 2,
414 'lvalue->$thing when lvalue returns array';
416 my @my = qw/ a b c /;
417 sub lvmya : lvalue { @my }
419 is lvmya->${\sub { return $_[0] }}, 3,
420 'lvalue->$thing when lvalue returns lexical array';
422 sub lv1n : lvalue { $newvar }
425 eval <<'EOE' or $_ = $@;
430 is("'$newvar' $_", "'4' ");
432 sub lv1nn : lvalue { $nnewvar }
435 eval <<'EOE' or $_ = $@;
440 is("'$nnewvar' $_", "'3' ");
446 eval 'sub AUTOLOAD : lvalue { $newvar }';
450 # But autoloading should only be triggered by a call to an undefined
453 is $newvar, 12, 'AUTOLOAD does not take precedence over lvalue sub';
454 eval { &{"xxx"} = 14 };
455 is $newvar, 12, 'AUTOLOAD does not take precedence over non-lvalue sub';
459 sub alv : lvalue { $array[1] }
460 sub alv2 : lvalue { $array[$_[0]] }
461 sub hlv : lvalue { $hash{"foo"} }
462 sub hlv2 : lvalue { $hash{$_[0]} }
463 $array[1] = "not ok 51\n";
465 is(alv(), "ok 50\n");
467 alv2(20) = "ok 51\n";
468 is($array[20], "ok 51\n");
470 $hash{"foo"} = "not ok 52\n";
472 is($hash{foo}, "ok 52\n");
474 $hash{bar} = "not ok 53\n";
475 hlv("bar") = "ok 53\n";
476 is(hlv("bar"), "ok 53\n");
478 sub array : lvalue { @array }
479 sub array2 : lvalue { @array2 } # This is a global.
480 sub hash : lvalue { %hash }
481 sub hash2 : lvalue { %hash2 } # So's this.
482 @array2 = qw(foo bar);
483 %hash2 = qw(foo bar);
485 (array()) = qw(ok 54);
486 is("@array", "ok 54");
488 (array2()) = qw(ok 55);
489 is("@array2", "ok 55");
491 (hash()) = qw(ok 56);
492 cmp_ok($hash{ok}, '==', 56);
494 (hash2()) = qw(ok 57);
495 cmp_ok($hash2{ok}, '==', 57);
497 @array = qw(a b c d);
498 sub aslice1 : lvalue { @array[0,2] };
499 (aslice1()) = ("ok", "already");
500 is("@array", "ok b already d");
502 @array2 = qw(a B c d);
503 sub aslice2 : lvalue { @array2[0,2] };
504 (aslice2()) = ("ok", "already");
505 is("@array2", "ok B already d");
507 %hash = qw(a Alpha b Beta c Gamma);
508 sub hslice : lvalue { @hash{"c", "b"} }
509 (hslice()) = ("CISC", "BogoMIPS");
510 is(join("/",@hash{"c","a","b"}), "CISC/Alpha/BogoMIPS");
513 $str = "Hello, world!";
514 sub sstr : lvalue { substr($str, 1, 4) }
516 is($str, "Hi, world!");
518 $str = "Made w/ JavaScript";
519 sub veclv : lvalue { vec($str, 2, 32) }
520 if (ord('A') != 193) {
521 veclv() = 0x5065726C;
524 veclv() = 0xD7859993;
526 is($str, "Made w/ PerlScript");
528 sub position : lvalue { pos }
530 $_ = "fee fi fo fum";
537 sub keeze : lvalue { keys %__ }
540 is scalar %__, '1/64', 'keys assignment through lvalue sub';
542 # Bug 20001223.002: split thought that the list had only one element
544 sub lval1 : lvalue { $ary[0]; }
545 sub lval2 : lvalue { $ary[1]; }
546 (lval1(), lval2()) = split ' ', "1 2 3 4";
548 is(join(':', @ary), "1:2:6");
550 # check that an element of a tied hash/array can be assigned to via lvalueness
555 sub TIEHASH { bless \my $v => __PACKAGE__ }
556 sub STORE { ($key, $val) = @_[1,2] }
559 sub lval_tie_hash : lvalue {
560 tie my %t => 'Tie_Hash';
564 eval { lval_tie_hash() = "value"; };
566 is($@, "", "element of tied hash");
568 is("$Tie_Hash::key-$Tie_Hash::val", "key-value");
574 sub TIEARRAY { bless \my $v => __PACKAGE__ }
575 sub STORE { $val[ $_[1] ] = $_[2] }
578 sub lval_tie_array : lvalue {
579 tie my @t => 'Tie_Array';
583 eval { lval_tie_array() = "value"; };
586 is($@, "", "element of tied array");
588 is ($Tie_Array::val[0], "value");
591 # Check that tied pad vars that are returned can be assigned to
592 sub TIESCALAR { bless [] }
593 sub STORE {$wheel = $_[1]}
595 sub tied_pad_var :lvalue { tie my $tyre, ''; $tyre }
596 sub tied_pad_varr :lvalue { tie my $tyre, ''; return $tyre }
598 is $wheel, 1, 'tied pad var returned in scalar lvalue context';
599 tied_pad_var->${\sub{ $_[0] = 2 }};
600 is $wheel, 2, 'tied pad var returned in scalar ref context';
602 is $wheel, 3, 'tied pad var returned in list lvalue context';
603 $_ = 4 for tied_pad_var;
604 is $wheel, 4, 'tied pad var returned in list ref context';
606 is $wheel, 5, 'tied pad var explicitly returned in scalar lvalue context';
607 tied_pad_varr->${\sub{ $_[0] = 6 }};
608 is $wheel, 6, 'tied pad var explicitly returned in scalar ref context';
610 is $wheel, 7, 'tied pad var explicitly returned in list lvalue context';
611 $_ = 8 for tied_pad_varr;
612 is $wheel, 8, 'tied pad var explicitly returned in list ref context';
615 # Test explicit return of lvalue expression
617 # subs are copies from tests 1-~18 with an explicit return added.
618 # They used not to work, which is why they are ‘badly’ named.
619 sub bad_get_lex : lvalue { return $in };
620 sub bad_get_st : lvalue { return $blah }
622 sub bad_id : lvalue { return ${\shift} }
623 sub bad_id1 : lvalue { return $_[0] }
624 sub bad_inc : lvalue { return ${\++$_[0]} }
639 is($blah, 8, "yada");
642 cmp_ok($in, '==', 8);
644 bad_id(bad_get_st) = 10;
645 cmp_ok($blah, '==', 10);
647 bad_id(bad_get_lex) = 10;
648 cmp_ok($in, '==', 10);
650 ++bad_id(bad_get_st);
651 cmp_ok($blah, '==', 11);
653 ++bad_id(bad_get_lex);
654 cmp_ok($in, '==', 11);
656 bad_id1(bad_get_st) = 20;
657 cmp_ok($blah, '==', 20);
659 bad_id1(bad_get_lex) = 20;
660 cmp_ok($in, '==', 20);
662 ++bad_id1(bad_get_st);
663 cmp_ok($blah, '==', 21);
665 ++bad_id1(bad_get_lex);
666 cmp_ok($in, '==', 21);
669 cmp_ok($blah, '==', 22);
671 bad_inc(bad_get_lex);
672 cmp_ok($in, '==', 22);
674 bad_inc(bad_id(bad_get_st));
675 cmp_ok($blah, '==', 23);
677 bad_inc(bad_id(bad_get_lex));
678 cmp_ok($in, '==', 23);
680 ++bad_inc(bad_id1(bad_id(bad_get_st)));
681 cmp_ok($blah, '==', 25);
683 ++bad_inc(bad_id1(bad_id(bad_get_lex)));
684 cmp_ok($in, '==', 25);
690 my $depth = shift//0;
691 if ($depth == 2) { return $to_modify }
692 return &$r($depth+1);
695 is $to_modify, 7, 'recursive lvalue sub';
697 # Recursive with substr [perl #72706]
702 return &$pie($depth) if $depth--;
705 for my $depth (0, 1, 2) {
706 my $value = "Good $depth";
708 &$pie($depth) = $value;
710 is($@, '', "recursive lvalue substr return depth $depth");
712 "value assigned to recursive lvalue substr (depth $depth)");
717 my @arr = qw /one two three/;
719 sub lval_array () : lvalue {@arr}
725 is($line, "zeroonetwothree");
727 sub trythislval { scalar(@_)."x".join "", @_ }
728 is(trythislval(lval_array()), "3xonetwothree");
730 sub changeme { $_[2] = "free" }
731 changeme(lval_array);
732 is("@arr", "one two free");
734 # test again, with explicit return
735 sub rlval_array() : lvalue {return @arr}
736 @arr = qw /one two three/;
741 is($line, "zeroonetwothree");
742 is(trythislval(rlval_array()), "3xonetwothree");
743 changeme(rlval_array);
744 is("@arr", "one two free");
746 # Variations on the same theme, with multiple vars returned
748 sub lval_scalar_array () : lvalue { $scalar, @arr }
749 @arr = qw /one two three/;
751 for (lval_scalar_array) {
754 is($line, "zerohalfonetwothree");
755 is(trythislval(lval_scalar_array()), "4xhalfonetwothree");
756 changeme(lval_scalar_array);
757 is("@arr", "one free three");
759 sub lval_array_scalar () : lvalue { @arr, $scalar }
760 @arr = qw /one two three/;
763 for (lval_array_scalar) {
766 is($line, "zeroonetwothreefour");
767 is(trythislval(lval_array_scalar()), "4xonetwothreefour");
768 changeme(lval_array_scalar);
769 is("@arr", "one two free");
771 # Tests for specific ops not tested above
773 @array2 = qw 'one two free';
774 is join(',', map $_, sub:lvalue{@array2}->()), 'one,two,free',
775 'rv2av in reference context';
776 is join(',', map $_, sub:lvalue{@{\@array2}}->()), 'one,two,free',
777 'rv2av-with-ref in reference context';
779 my %hash = qw[a b c d];
780 like join(',', map $_, sub:lvalue{%hash}->()),
781 qr/^(?:a,b,c,d|c,d,a,b)\z/, 'padhv in reference context';
783 %hash2 = qw[a b c d];
784 like join(',', map $_, sub:lvalue{%hash2}->()),
785 qr/^(?:a,b,c,d|c,d,a,b)\z/, 'rv2hv in reference context';
786 like join(',', map $_, sub:lvalue{%{\%hash2}}->()),
787 qr/^(?:a,b,c,d|c,d,a,b)\z/, 'rv2hv-with-ref in reference context';
792 sub AUTOLOAD :lvalue { *{$AUTOLOAD} };
794 my $foo = bless {},"Foo";
796 $foo->bar = sub { $result = "bar" };
798 is ($result, 'bar', "RT #41550");
801 SKIP: { skip 'no attributes.pm', 1 unless eval 'require attributes';
802 fresh_perl_is(<<'----', <<'====', {}, "lvalue can not be set after definition. [perl #68758]");
807 sub MODIFY_CODE_ATTRIBUTES {}
808 sub foo : lvalue : fr0g;
811 lvalue attribute ignored after the subroutine has been defined at - line 4.
812 lvalue attribute ignored after the subroutine has been defined at - line 6.
813 Can't modify non-lvalue subroutine call in scalar assignment at - line 7, near "3;"
814 Execution of - aborted due to compilation errors.
820 sub lval_decl : lvalue;
823 is($x, 5, "subroutine declared with lvalue before definition retains lvalue. [perl #68758]");
826 SKIP: { skip "no attributes.pm", 2 unless eval { require attributes };
827 sub utf8::valid :lvalue;
829 is "@{[ &attributes::get(\&utf8::valid) ]}", 'lvalue',
830 'sub declaration with :lvalue applies it to XSUBs';
832 BEGIN { *wonky = \&marjibberous }
834 is "@{[ &attributes::get(\&wonky) ]}", 'lvalue',
835 'sub declaration with :lvalue applies it to assigned stub';
838 sub fleen : lvalue { $pnare }
839 $pnare = __PACKAGE__;
840 ok eval { fleen = 1 }, "lvalues can return COWs (CATTLE?) [perl #75656]";\
841 is $pnare, 1, 'and returning CATTLE actually works';
842 $pnare = __PACKAGE__;
843 ok eval { (fleen) = 1 }, "lvalues can return COWs in list context";
844 is $pnare, 1, 'and returning COWs in list context actually works';
845 $pnare = __PACKAGE__;
846 ok eval { $_ = 1 for(fleen); 1 }, "lvalues can return COWs in ref cx";
847 is $pnare, 1, 'and returning COWs in reference context actually works';
850 # Returning an arbitrary expression, not necessarily lvalue
851 +sub :lvalue { return $ambaga || $ambaga }->() = 73;
852 is $ambaga, 73, 'explicit return of arbitrary expression (scalar context)';
853 (sub :lvalue { return $ambaga || $ambaga }->()) = 74;
854 is $ambaga, 74, 'explicit return of arbitrary expression (list context)';
855 +sub :lvalue { $ambaga || $ambaga }->() = 73;
856 is $ambaga, 73, 'implicit return of arbitrary expression (scalar context)';
857 (sub :lvalue { $ambaga || $ambaga }->()) = 74;
858 is $ambaga, 74, 'implicit return of arbitrary expression (list context)';
859 eval { +sub :lvalue { return 3 }->() = 4 };
860 like $@, qr/Can\'t return a readonly value from lvalue subroutine at/,
861 'assignment to numeric constant explicitly returned from lv sub';
862 eval { (sub :lvalue { return 3 }->()) = 4 };
863 like $@, qr/Can\'t return a readonly value from lvalue subroutine at/,
864 'assignment to num constant explicitly returned (list cx)';
865 eval { +sub :lvalue { 3 }->() = 4 };
866 like $@, qr/Can\'t return a readonly value from lvalue subroutine at/,
867 'assignment to numeric constant implicitly returned from lv sub';
868 eval { (sub :lvalue { 3 }->()) = 4 };
869 like $@, qr/Can\'t return a readonly value from lvalue subroutine at/,
870 'assignment to num constant implicitly returned (list cx)';
872 # reference (potential lvalue) context
874 for my $sub (sub :lvalue {$_}, sub :lvalue {return $_}) {
875 &$sub()->${\sub { $_[0] = 37 }};
876 is $_, '37', 'lvalue->method'.$suffix;
877 ${\scalar &$sub()} = 38;
878 is $_, '38', 'scalar(lvalue)'.$suffix;
879 sub assign39_with_proto ($) { $_[0] = 39 }
880 assign39_with_proto(&$sub());
881 is $_, '39', 'func(lvalue) when func has $ proto'.$suffix;
883 ${\(&$sub()||undef)} = 40;
884 is $_, '40', 'lvalue||...'.$suffix;
885 ${\(${\undef}||&$sub())} = 41; # extra ${\...} to bypass const folding
886 is $_, '41', '...||lvalue'.$suffix;
888 ${\(&$sub()&&undef)} = 42;
889 is $_, '42', 'lvalue&&...'.$suffix;
890 ${\(${\1}&&&$sub())} = 43;
891 is $_, '43', '...&&lvalue'.$suffix;
892 ${\(&$sub())[0]} = 44;
893 is $_, '44', '(lvalue)[0]'.$suffix;
895 continue { $suffix = ' (explicit return)' }
899 for my $sub (sub :lvalue {$_}, sub :lvalue {return $_}) {
902 is $_->[3], 4, 'func->[...] autovivification'.$suffix;
905 is $_->{3}, 4, 'func->{...} autovivification'.$suffix;
908 is $$_, 4, '${func()} autovivification' .$suffix;
911 is "@$_", 4, '@{func()} autovivification' .$suffix;
914 is join('-',%$_), '4-5', '%{func()} autovivification'.$suffix;
917 is $$_, 4, '${ (), func()} autovivification' .$suffix;
919 continue { $suffix = ' (explicit return)' }
921 # [perl #92406] [perl #92290] Returning a pad var in rvalue context
924 sub :lvalue { my $x = 72; $x },
925 sub :lvalue { my $x = 72; return $x }
927 is scalar(&$sub), 72, "sub returning pad var in scalar context$suffix";
928 is +(&$sub)[0], 72, "sub returning pad var in list context$suffix";
930 continue { $suffix = ' (explicit return)' }
932 # Returning read-only values in reference context
935 sub :lvalue { $] }->(),
936 sub :lvalue { return $] }->()
938 is \$_, \$], 'read-only values are returned in reference context'
939 .$suffix # (they used to be copied)
941 continue { $suffix = ' (explicit return)' }
943 # Returning unwritables from nested lvalue sub call in in rvalue context
944 # First, ensure we are testing what we think we are:
945 if (!Internals::SvREADONLY($])) { Internals::SvREADONLY($],1); }
946 sub squibble : lvalue { return $] }
947 sub squebble : lvalue { squibble }
948 sub squabble : lvalue { return squibble }
949 is $x = squebble, $], 'returning ro from nested lv sub call in rv cx';
950 is $x = squabble, $], 'explct. returning ro from nested lv sub in rv cx';
951 is \squebble, \$], 'returning ro from nested lv sub call in ref cx';
952 is \squabble, \$], 'explct. returning ro from nested lv sub in ref cx';
954 # [perl #102486] Sub calls as the last statement of an lvalue sub
958 sub strictlv :lvalue { use strict 'refs'; &$x }
959 sub lv :lvalue { &$x }
960 sub nonlv { ++$called }
962 ::like $@, qr/^Can't use string \("nonlv"\) as a subroutine ref while/,
963 'strict mode applies to sub:lvalue{ &$string }';
966 'sub:lvalue{&$x}->() does not die for non-lvalue inner sub call';
967 ::is $called, 1, 'The &$x actually called the sub';
968 eval { +sub :lvalue { &$x }->() = 3 };
969 ::like $@, qr/^Can't modify non-lvalue subroutine call at /,
970 'sub:lvalue{&$x}->() dies in true lvalue context';
973 # TARG should be copied in rvalue context
974 sub ucf :lvalue { ucfirst $_[0] }
975 is ucf("just another ") . ucf("perl hacker,\n"),
976 "Just another Perl hacker,\n", 'TARG is copied in rvalue scalar cx';
977 is join('',ucf("just another "), ucf "perl hacker,\n"),
978 "Just another Perl hacker,\n", 'TARG is copied in rvalue list cx';
980 @_ ? ucfirst $_[0] : do {
981 is ucfr("just another ") . ucfr("perl hacker,\n"),
982 "Just another Perl hacker,\n",
983 'TARG is copied in recursive rvalue scalar cx';
984 is join('',ucfr("just another "), ucfr("perl hacker,\n")),
985 "Just another Perl hacker,\n",
986 'TARG is copied in recursive rvalue list cx';
991 # Test TARG with potential lvalue context, too
992 for (sub : lvalue { "$x" }->()) {
993 is \$_, \$_, '\$_ == \$_ in for(sub :lvalue{"$x"}->()){...}'
996 # [perl #117947] XSUBs should not be treated as lvalues at run time
997 eval { &{\&utf8::is_utf8}("") = 3 };
998 like $@, qr/^Can't modify non-lvalue subroutine call at /,
999 'XSUB not seen at compile time dies in lvalue context';
1001 # [perl #119797] else implicitly returning value
1002 # This used to cause Bizarre copy of ARRAY in pp_leave
1003 sub else119797 : lvalue {
1005 1; # two statements force a leave op
1012 eval { (else119797(0)) = 1..3 };
1013 is $@, "", '$@ after writing to array returned by else';
1014 is "@119797", "1 2 3", 'writing to array returned by else';
1015 eval { (else119797(1)) = 4..6 };
1016 is $@, "", '$@ after writing to array returned by if (with else)';
1017 is "@119797", "4 5 6", 'writing to array returned by if (with else)';
1018 sub if119797 : lvalue {
1024 eval { (if119797(1)) = 4..6 };
1025 is $@, "", '$@ after writing to array returned by if';
1026 is "@119797", "4 5 6", 'writing to array returned by if';
1027 sub unless119797 : lvalue {
1033 eval { (unless119797(0)) = 4..6 };
1034 is $@, "", '$@ after writing to array returned by unless';
1035 is "@119797", "4 5 6", 'writing to array returned by unless';
1036 sub bare119797 : lvalue {
1042 eval { (bare119797(0)) = 4..6 };
1043 is $@, "", '$@ after writing to array returned by bare block';
1044 is "@119797", "4 5 6", 'writing to array returned by bare block';