develooper Front page | perl.perl5.porters | Postings from October 2013

[perl #120112] [PATCH] 4672385 "foreach my TYPE" sometimes raises wrong syntax error.

Thread Next
From:
hio @ hio . jp
Date:
October 6, 2013 05:46
Subject:
[perl #120112] [PATCH] 4672385 "foreach my TYPE" sometimes raises wrong syntax error.
Message ID:
rt-3.6.HEAD-26210-1380988370-1240.120112-75-0@perl.org
# New Ticket Created by  hio@hio.jp 
# Please include the string:  [perl #120112]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=120112 >



This is a bug report for perl from hio@hio.jp,
generated with the help of perlbug 1.39 running under perl 5.19.5.

>From 46723851687cab39fb7364207bab4b6b8dcecd51 Mon Sep 17 00:00:00 2001
From: YAMASHINA Hio <hio@hio.jp>
Date: Sun, 6 Oct 2013 07:18:02 +0900
Subject: [PATCH] "foreach my TYPE" sometimes raises wrong syntax error.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.1"

This is a multi-part message in MIME format.
--------------1.7.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


When second character of TYPE is a digit followed by alphabet,
perl raises compile time error with "Missing $ on loop variable".

$ perl -e 'package a1;  foreach my a1  $i (1) {}'
(ok)

$ perl -e 'package a1b; foreach my a1b $i (1) {}'
Missing $ on loop variable at -e line 1.

This is caused by scan_ident is used for parse TYPE.
But scan_ident expects identi with sigil.
It seems scan_word should be used.

There is two tests in t/comp/parser.t.
It seems these are intended to test for scan_ident
though this patch replaces scan_ident to scan_word.
---
 t/comp/parser.t |   12 ++++++++----
 toke.c          |    2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)


--------------1.7.1
Content-Type: text/x-patch; name="0001-foreach-my-TYPE-sometimes-raises-wrong-syntax-error.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-foreach-my-TYPE-sometimes-raises-wrong-syntax-error.patch"

diff --git a/t/comp/parser.t b/t/comp/parser.t
index 8fd7e85..7caa116 100644
--- a/t/comp/parser.t
+++ b/t/comp/parser.t
@@ -8,7 +8,7 @@ BEGIN {
     chdir 't';
 }
 
-print "1..168\n";
+print "1..169\n";
 
 sub failed {
     my ($got, $expected, $name) = @_;
@@ -333,10 +333,10 @@ like($@, qr/BEGIN failed--compilation aborted/, 'BEGIN 7' );
   eval qq[ *$xFD ];
   like($@, qr/Identifier too long/, "too long id in glob ctx");
 
-  eval qq[ for $xFD ];
+  eval qq[ for $xFC ];
   like($@, qr/Missing \$ on loop variable/,
-       "253 char id ok, but a different error");
-  eval qq[ for $xFE; ];
+       "252 char id ok, but a different error");
+  eval qq[ for $xFD; ];
   like($@, qr/Identifier too long/, "too long id in for ctx");
 
   # the specific case from the ticket
@@ -495,6 +495,10 @@ eval 'Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo'
     .'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo';
 like $@, "^Identifier too long at ", 'ident buffer overflow';
 
+eval 'for my a1b $i (1) {}';
+# ng: 'Missing $ on loop variable'
+like $@, "^No such class a1b at ", 'TYPE of my of for statement';
+
 # Add new tests HERE (above this line)
 
 # bug #74022: Loop on characters in \p{OtherIDContinue}
diff --git a/toke.c b/toke.c
index 97205a3..d2a2fd6 100644
--- a/toke.c
+++ b/toke.c
@@ -7970,7 +7970,7 @@ Perl_yylex(pTHX)
 		    p += 3;
 		p = PEEKSPACE(p);
 		if (isIDFIRST_lazy_if(p,UTF)) {
-		    p = scan_ident(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE);
+		    p = scan_word(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len);
 		    p = PEEKSPACE(p);
 		}
 		if (*p != '$')

--------------1.7.1--


---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.19.5:

Configured by root at Sun Oct  6 07:28:11 JST 2013.

Summary of my perl5 (revision 5 version 19 subversion 5) configuration:
  Commit id: 73b273f5b2a4c0d9096d36bb8e870486c977ad7a
  Platform:
    osname=linux, osvers=2.6.32-358.18.1.el6.x86_64, archname=x86_64-linux
    uname='linux localhost.localdomain 2.6.32-358.18.1.el6.x86_64 #1 smp wed aug 28 17:19:38 utc 2013 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.7 20120313 (Red Hat 4.4.7-3)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.12'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'


---
@INC for perl 5.19.5:
    /usr/local/lib/perl5/site_perl/5.19.5/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.19.5
    /usr/local/lib/perl5/5.19.5/x86_64-linux
    /usr/local/lib/perl5/5.19.5
    .

---
Environment for perl 5.19.5:
    HOME=/home/hio
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hio/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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