lvalue AUTOLOAD. No, really.
authorSimon Cozens <simon@netthink.co.uk>
Wed, 27 Dec 2000 02:30:03 +0000 (02:30 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 28 Dec 2000 22:59:16 +0000 (22:59 +0000)
Message-ID: <20001227023003.A7677@deep-dark-truthful-mirror.perlhacker.org>

p4raw-id: //depot/perl@8243

pp.c
t/pragma/sub_lval.t

diff --git a/pp.c b/pp.c
index 2cb463e..8914104 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -385,8 +385,12 @@ PP(pp_rv2cv)
     if (cv) {
        if (CvCLONE(cv))
            cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
-       if ((PL_op->op_private & OPpLVAL_INTRO) && !CvLVALUE(cv))
-           DIE(aTHX_ "Can't modify non-lvalue subroutine call");
+       if ((PL_op->op_private & OPpLVAL_INTRO)) {
+           if (gv && GvCV(gv) == cv && (gv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), FALSE)))
+               cv = GvCV(gv);
+           if (!CvLVALUE(cv))
+               DIE(aTHX_ "Can't modify non-lvalue subroutine call");
+       }
     }
     else
        cv = (CV*)&PL_sv_undef;
index 660e72d..1b8b73a 100755 (executable)
@@ -1,4 +1,4 @@
-print "1..46\n";
+print "1..47\n";
 
 BEGIN {
     chdir 't' if -d 't';
@@ -427,3 +427,12 @@ $a = \&lv1nn;
 $a->() = 8;
 print "# '$nnewvar'.\nnot " unless $nnewvar eq '8';
 print "ok 46\n";
+
+# This must happen at run time
+eval {
+    sub AUTOLOAD : lvalue { $newvar };
+};
+foobar() = 12;
+print "# '$newvar'.\nnot " unless $newvar eq "12";
+print "ok 47\n";
+