This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 19991001.003] sort(sub(arg)) misparsed as sort sub args
authorSimon Cozens <simon@netthink.co.uk>
Wed, 27 Dec 2000 14:12:44 +0000 (14:12 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 28 Dec 2000 22:37:45 +0000 (22:37 +0000)
Message-ID: <20001227141244.A13344@deep-dark-truthful-mirror.perlhacker.org>

p4raw-id: //depot/perl@8239

t/op/method.t
t/op/sort.t
toke.c

index be4df75..1f5cbb6 100755 (executable)
@@ -9,7 +9,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-print "1..53\n";
+print "1..54\n";
 
 @A::ISA = 'B';
 @B::ISA = 'C';
@@ -185,3 +185,8 @@ test(do { eval 'E->foo()';
 test(do { eval '$e = bless {}, "E"; $e->foo()';
          $@ =~ /^\QCan't locate object method "foo" via package "E" (perhaps / ? 1 : $@}, 1);
 
+# This is actually testing parsing of indirect objects and undefined subs
+#   print foo("bar") where foo does not exist is not an indirect object.
+#   print foo "bar"  where foo does not exist is an indirect object.
+eval { sub AUTOLOAD { "ok ", shift, "\n"; } };
+print nonsuch(++$cnt);
index 9095871..c1dfb63 100755 (executable)
@@ -5,7 +5,7 @@ BEGIN {
     @INC = '../lib';
 }
 use warnings;
-print "1..57\n";
+print "1..58\n";
 
 # XXX known to leak scalars
 {
@@ -321,3 +321,10 @@ sub cxt_six { sort test_if_scalar 1,2 }
     print "# x = '@b'\n";
     print !$def ? "ok 57\n" : "not ok 57\n";
 }
+
+# Bug 19991001.003
+{
+    sub routine { "one", "two" };
+    @a = sort(routine(1));
+    print "@a" eq "one two" ? "ok 58\n" : "not ok 58\n";
+}
diff --git a/toke.c b/toke.c
index cd6ed1d..46278e8 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3915,10 +3915,10 @@ Perl_yylex(pTHX)
                    /* If not a declared subroutine, it's an indirect object. */
                    /* (But it's an indir obj regardless for sort.) */
 
-                   if ((PL_last_lop_op == OP_SORT ||
-                         (!immediate_paren && (!gv || !GvCVu(gv)))) &&
+                   if ( !immediate_paren && (PL_last_lop_op == OP_SORT || 
+                         ((!gv || !GvCVu(gv)) &&
                         (PL_last_lop_op != OP_MAPSTART &&
-                        PL_last_lop_op != OP_GREPSTART))
+                        PL_last_lop_op != OP_GREPSTART))))
                    {
                        PL_expect = (PL_last_lop == PL_oldoldbufptr) ? XTERM : XOPERATOR;
                        goto bareword;