develooper Front page | perl.perl5.porters | Postings from December 2001

PATCH: Restore "Can't declare scalar dereference in my" error

Thread Next
From:
Mark-Jason Dominus
Date:
December 24, 2001 15:13
Subject:
PATCH: Restore "Can't declare scalar dereference in my" error
Message ID:
20011224231448.25826.qmail@plover.com

Up until about 5.005_63, the following were forbidden:

        my $$x;
        my @$x;
        my %$x;
        my $$$x;
        (etc.)

At that time, this error was eliminated.

The enclosed patch restores this error.

Notes:

1. All tests pass.

2. The new tests are in t/op/eval.t not because that is the right
   place for them, but because I did not know what the right place
   was.

3. It would be good if this patch could be vetted by someone who
   actually knows what they are doing.   I am not that person.


--- op.c	2001/12/24 22:56:22	1.1
+++ op.c	2001/12/24 22:56:27
@@ -2043,6 +2043,9 @@
     } else if (type == OP_RV2SV ||	/* "our" declaration */
 	       type == OP_RV2AV ||
 	       type == OP_RV2HV) { /* XXX does this let anything illegal in? */
+      if (cUNOPo->op_first->op_type != OP_GV) { /* MJD 20011224 */
+           yyerror(form("Can't declare %s in my", OP_DESC(o)));
+        }
         if (attrs) {
             GV *gv = cGVOPx_gv(cUNOPo->op_first);
             PL_in_my = FALSE;
--- t/op/eval.t	2001/12/24 21:41:38	1.1
+++ t/op/eval.t	2001/12/24 22:21:12
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..41\n";
+print "1..45\n";
 
 eval 'print "ok 1\n";';
 
@@ -220,4 +220,17 @@
 	}
     };
     print "not ok 41\n" if $@;
+}
+
+# Make sure that "my $$x" is forbidden
+# 20011224 MJD
+{
+  eval q{my $$x};
+  print $@ ? "ok 42\n" : "not ok 42\n";
+  eval q{my @$x};
+  print $@ ? "ok 43\n" : "not ok 43\n";
+  eval q{my %$x};
+  print $@ ? "ok 44\n" : "not ok 44\n";
+  eval q{my $$$x};
+  print $@ ? "ok 45\n" : "not ok 45\n";
 }

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About