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

42->{42} works in strict mode #13218

Open
p5pRT opened this issue Aug 31, 2013 · 4 comments
Open

42->{42} works in strict mode #13218

p5pRT opened this issue Aug 31, 2013 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 31, 2013

Migrated from rt.perl.org#119547 (status was 'open')

Searchable as RT119547$

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2013

From glitchmr@myopera.com

Created by glitchmr@myopera.com

Following code doesn't fail, when it should (42 is symbolic ref)

  use strict;
  42->{42};

This code also doesn't fail.

  use strict;
  sub CONSTANT() { 42 }
  CONSTANT->{42};

But this does correctly fail.

  use strict;
  sub { 42 }->()->{42};
  # Can't use string ("42") as a HASH ref while "strict refs" in
  use...

 

Perl Info

Flags:
    category=library
    severity=medium
    module=strict

Site configuration information for perl 5.18.1:

Configured by nobody at Tue Aug 13 13:22:58 CEST 2013.

Summary of my perl5 (revision 5 version 18 subversion 1) configuration:
   
  Platform:
    osname=linux, osvers=3.10.5-1-arch,
    archname=x86_64-linux-thread-multi
    uname='linux mnt-chroots-arch-extra-x86_64-flo-64 3.10.5-1-arch #1
    smp preempt mon aug 5 08:04:22 cest 2013 x86_64 gnulinux '
    config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64
    -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4
    -Dprefix=/usr -Dvendorprefix=/usr
    -Dprivlib=/usr/share/perl5/core_perl
    -Darchlib=/usr/lib/perl5/core_perl
    -Dsitelib=/usr/share/perl5/site_perl
    -Dsitearch=/usr/lib/perl5/site_perl
    -Dvendorlib=/usr/share/perl5/vendor_perl
    -Dvendorarch=/usr/lib/perl5/vendor_perl
    -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl
    -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none
    -Dman1ext=1perl -Dman3ext=3perl -Dcccdlflags='-fPIC'
    -Dlddlflags=-shared -Wl,-O1,--sort-common,--as-needed,-z,relro
    -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
    -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
    -D_FILE_OFFSET_BITS=64',
    optimize='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector
    --param=ssp-buffer-size=4',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
    -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.1 20130725 (prerelease)',
    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 ='-Wl,-O1,--sort-common,--as-needed,-z,relro
    -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib
    /lib64 /usr/lib64
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.17.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.17'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
    -Wl,-rpath,/usr/lib/perl5/core_perl/CORE'
    cccdlflags='-fPIC', lddlflags='-shared
    -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib
    -fstack-protector'

Locally applied patches:
    


@INC for perl 5.18.1:
    /home/glitchmr/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/glitchmr/perl5/lib/perl5
    /usr/lib/perl5/site_perl
    /usr/share/perl5/site_perl
    /usr/lib/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/core_perl
    /usr/share/perl5/core_perl
    .


Environment for perl 5.18.1:
    HOME=/home/glitchmr
    LANG=pl_PL.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/lib/colorgcc/bin:/home/glitchmr/.gem/ruby/2.0.0/bin:/home/glitchmr/perl5/bin:/usr/bin/vendor_perl:/usr/bin
    PERL5LIB=/home/glitchmr/perl5/lib/perl5
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=:/home/glitchmr/perl5
    PERL_MM_OPT=INSTALL_BASE=/home/glitchmr/perl5
    SHELL=/usr/bin/fish

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2013

From @doy

On Sat, Aug 31, 2013 at 12​:12​:16PM -0700, GlitchMr wrote​:

Following code doesn't fail, when it should (42 is symbolic ref)

use strict;
42\->\{42\};

This code also doesn't fail.

use strict;
sub CONSTANT\(\) \{ 42 \}
CONSTANT\->\{42\};

But this does correctly fail.

use strict;
sub \{ 42 \}\->\(\)\->\{42\};
\# Can't use string \("42"\) as a HASH ref while "strict refs" in
use\.\.\.

This bug appears to have been present for quite some time (if not
forever)​:

  $ perl -le'print $]'
  5.006002
  $ perl -le'*{"42"} = {foo => "bar"}; use strict; print 42->{foo}'
  bar
  $ perl -le'*{"42"} = {foo => "bar"}; use strict; print "42"->{foo}'
  bar
  $ perl -le'*{"42a"} = {foo => "bar"}; use strict; print "42a"->{foo}'
  bar
  $ perl -le'*{"a"} = {foo => "bar"}; use strict; print "a"->{foo}'
  Global symbol "%a" requires explicit package name at -e line 1.
  Execution of -e aborted due to compilation errors.

-doy

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 31, 2013

From @cpansprout

On Sat Aug 31 12​:24​:23 2013, doy@​tozt.net wrote​:

On Sat, Aug 31, 2013 at 12​:12​:16PM -0700, GlitchMr wrote​:

Following code doesn't fail, when it should (42 is symbolic ref)

use strict;
42\->\{42\};

This code also doesn't fail.

use strict;
sub CONSTANT\(\) \{ 42 \}
CONSTANT\->\{42\};

But this does correctly fail.

use strict;
sub \{ 42 \}\->\(\)\->\{42\};
\# Can't use string \("42"\) as a HASH ref while "strict refs" in
use\.\.\.

This bug appears to have been present for quite some time (if not
forever)​:

$ perl -le'print $]'
5.006002
$ perl -le'*{"42"} = {foo => "bar"}; use strict; print 42->{foo}'
bar
$ perl -le'*{"42"} = {foo => "bar"}; use strict; print "42"->{foo}'
bar
$ perl -le'*{"42a"} = {foo => "bar"}; use strict; print "42a"->{foo}'
bar
$ perl -le'*{"a"} = {foo => "bar"}; use strict; print "a"->{foo}'
Global symbol "%a" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.

As currently implemented, "a"->{foo} is subject to strict vars, not refs.

The parser loses the distinction between "a" and the ‘a’ in $a very
early on (they both compile down to const ops). This is very
longstanding behaviour. Do we want to change it? I have sometimes used
INC->{...} instead of $INC{...}, though probably only in one-liners.

--

Father Chrysostomos

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

2 participants