Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$ref->$var = $$var produces unexpected optree near method call #4368

Closed
p5pRT opened this issue Sep 2, 2001 · 9 comments
Closed

$ref->$var = $$var produces unexpected optree near method call #4368

p5pRT opened this issue Sep 2, 2001 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 2, 2001

Migrated from rt.perl.org#7609 (status was 'resolved')

Searchable as RT7609$

@p5pRT
Copy link
Author

p5pRT commented Sep 2, 2001

From anthony@asd.ppp0.com

Here is a complete test script​:

$ref->$var = $$var;

The result of perl -c on this is​:

panic​: unexpected optree near method call at /tmp/test.pl line 1, near "$var;"
/tmp/test.pl had compilation errors.

Syntacticly, I don't think there is anything wrong above. Logically,
there is, but that's because it's a minimal testcase ;-)

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.1:

Configured by bod at Fri Jun 22 18:58:01 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.5-ac9, archname=i386-linux
    uname='linux duende 2.4.5-ac9 #1 thu jun 21 00:52:39 est 2001 i686 unknown '
    config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Dotherlibdirs=/usr/lib/perl5/5.6:/usr/lib/perl5/5.005 -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20010604 (Debian prerelease)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt
    perllibs=-ldl -lm -lc -lcrypt
    libc=/lib/libc-2.2.3.so, so=so, useshrplib=true, libperl=libperl.so.5.6.1
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.1:
    /usr/local/lib/perl/5.6.1
    /usr/local/share/perl/5.6.1
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.6.1
    /usr/share/perl/5.6.1
    /usr/local/lib/site_perl
    /usr/lib/perl5/5.6
    /usr/lib/perl5/5.005
    .


Environment for perl v5.6.1:
    HOME=/home/anthony
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/anthony/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 2, 2001

From @mjdominus

  x->$var = 1

produces the same result.

@p5pRT
Copy link
Author

p5pRT commented Sep 3, 2001

From [Unknown Contact. See original ticket]

Here is a complete test script​:

$ref->$var = $$var;

    x\->$var = 1 

produces the same result.

Damn! I'm always amazed at the quick response of the perl community!

And in the special case of $ref being a hash, $ref->{$var} = $$var doesn't
cause issues.

@p5pRT
Copy link
Author

p5pRT commented Sep 3, 2001

From @rgarcia

So let's remove the check !
With the patch below all tests still pass (with my config, linux/default).
Here's a small test script, that behaves as expected with the patch :

$x = 1;
sub f : lvalue { $x }
sub g { $x }
main->f = 2;
print "$x\n";
$r = \&f;
main->$r = 3;
print "$x\n";
eval 'main->g = 4';
print "$x - $@​";
$r = \&g;
eval 'main->$r = 5';
print "$x - $@​";

I suppose that something like this should be added to t/op/sub_lval.t.
Note that this patch looks a bit violent. I have the feeling
that removing this check is harmless, but I would like to hear comments.

Inline Patch
--- op.c.orig	Sun Sep  2 12:32:42 2001
+++ op.c	Mon Sep  3 14:43:43 2001
@@ -1444,11 +1444,6 @@
 		    {
 			UNOP *newop;
 
-			if (kid->op_sibling || kid->op_next != kid) {
-			    yyerror("panic: unexpected optree near method call");
-			    break;
-			}
-			
 			NewOp(1101, newop, 1, UNOP);
 			newop->op_type = OP_RV2CV;
 			newop->op_ppaddr = PL_ppaddr[OP_RV2CV];

@p5pRT
Copy link
Author

p5pRT commented Sep 3, 2001

From [Unknown Contact. See original ticket]

$x = 1;
sub f : lvalue { $x }
sub g { $x }
main->f = 2;
print "$x\n";
$r = \&f;
main->$r = 3;

I was using it as a name of a method, e.g.,

$f = new Foo​::Bar;
$g = "gg"
$f->$g = "aa";

A simular thing is on pp. 313 of the Camel book.

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2001

From @rgarcia

Yes, using a string or a coderef doesn't affect the behavior of the bug
(or of bleadperl + my patch).

Looking into this a little deeper, I have the feeling that the patch
I've proposed is a correct fix. If it's to be integrated, I'll provide
new tests.

The initial patch is here :
http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-08/msg00246.html

@p5pRT
Copy link
Author

p5pRT commented Nov 30, 2001

From @rgarcia

Shortly, the bug is a parser panic :

  $ perl -e '$x="y";main->$x=1'
  panic​: unexpected optree near method call at -e line 1, at EOF
  Execution of -e aborted due to compilation errors.

With the patch :

  $ bperl -e '$x="y";main->$x=1'
  Can't locate object method "y" via package "main" at -e line 1.

Inline Patch
--- t/op/method.t.orig	Fri Jul  6 15:56:23 2001
+++ t/op/method.t	Fri Nov 30 23:27:50 2001
@@ -9,7 +9,7 @@
     @INC = '../lib';
 }
 
-print "1..72\n";
+print "1..73\n";
 
 @A::ISA = 'B';
 @B::ISA = 'C';
@@ -239,5 +239,14 @@
 #   print foo "bar"  where foo does not exist is an indirect object.
 eval { sub AUTOLOAD { "ok ", shift, "\n"; } };
 print nonsuch(++$cnt);
+
+# Bug ID 20010902.002
+test (
+    eval q[
+	$x = 'x';
+	sub Foo::x : lvalue { $x }
+	Foo->$x = 'ok';
+    ] || $@, 'ok'
+);
 
 print "# $cnt tests completed\n";
--- op.c.orig	Thu Nov 22 05:48:18 2001
+++ op.c	Fri Nov 30 23:16:56 2001
@@ -1446,11 +1446,6 @@
 			|| kid->op_type == OP_METHOD)
 		    {
 			UNOP *newop;
-
-			if (kid->op_sibling || kid->op_next != kid) {
-			    yyerror("panic: unexpected optree near method call");
-			    break;
-			}
 			
 			NewOp(1101, newop, 1, UNOP);
 			newop->op_type = OP_RV2CV;

@p5pRT
Copy link
Author

p5pRT commented Dec 1, 2001

From @jhi

Thanks, applied.

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT p5pRT closed this as completed May 9, 2003
@p5pRT
Copy link
Author

p5pRT commented May 9, 2003

@cwest - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant