Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.92k stars 551 forks source link

The => operator doesn't quote v-strings in "use constant v1 => 42" #13511

Open p5pRT opened 10 years ago

p5pRT commented 10 years ago

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

Searchable as RT120941$

p5pRT commented 10 years ago

From lappy@zoffix.com

Created by zoffix@zoffix.com

The fat comma operator (=>) doesn't seem to quote v-strings when used in the "use BLAH v1 => 42" lines. A particular example is "use constant v1 => 42" The v1 should be quoted by the => operator\, but that line of code produces a syntax error​: "syntax error at -e line 1\, near "use constant v1 =>""

Perl Info ``` Flags: category=core severity=low Site configuration information for perl 5.18.1: Configured by zoffix at Wed Dec 25 05:35:45 UTC 2013. Summary of my perl5 (revision 5 version 18 subversion 1) configuration: Platform: osname=linux, osvers=3.11.6-x86_64-linode35, archname=x86_64-linux uname='linux li328-86 3.11.6-x86_64-linode35 #1 smp wed oct 23 15:24:17 edt 2013 x86_64 gnulinux ' config_args='-de -Dprefix=/home/zoffix/perl5/perlbrew/perls/perl-5.18.1 -Aeval:scriptdir=/home/zoffix/perl5/perlbrew/perls/perl-5.18.1/bin' 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.7.2', 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/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib 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.13' 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' Locally applied patches: @INC for perl 5.18.1: /home/zoffix/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1/x86_64-linux /home/zoffix/perl5/perlbrew/perls/perl-5.18.1/lib/site_perl/5.18.1 /home/zoffix/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1/x86_64-linux /home/zoffix/perl5/perlbrew/perls/perl-5.18.1/lib/5.18.1 . Environment for perl 5.18.1: HOME=/home/zoffix LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/zoffix/perl5/perlbrew/bin:/home/zoffix/perl5/perlbrew/perls/perl-5.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games PERLBREW_BASHRC_VERSION=0.67 PERLBREW_HOME=/home/zoffix/.perlbrew PERLBREW_MANPATH=/home/zoffix/perl5/perlbrew/perls/perl-5.18.1/man PERLBREW_PATH=/home/zoffix/perl5/perlbrew/bin:/home/zoffix/perl5/perlbrew/perls/perl-5.18.1/bin PERLBREW_PERL=perl-5.18.1 PERLBREW_ROOT=/home/zoffix/perl5/perlbrew PERLBREW_VERSION=0.67 PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 10 years ago

From @Leont

On Mon\, Jan 6\, 2014 at 5​:50 PM\, Zoffix Znet \perlbug\-followup@​perl\.orgwrote​:

The fat comma operator (=>) doesn't seem to quote v-strings when used in the "use BLAH v1 => 42" lines. A particular example is "use constant v1 => 42" The v1 should be quoted by the => operator\, but that line of code produces a syntax error​: "syntax error at -e line 1\, near "use constant v1 =>""

use optionally takes a version\, so that is parsed as «use \ \ \»\, and => is not a valid start of an expression.

Leon

p5pRT commented 10 years ago

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

p5pRT commented 10 years ago

From @sciurius

Leon Timmermans \fawaka@​gmail\.com writes​:

use optionally takes a version\, so that is parsed as «use \ \ \»\, and => is not a valid start of an expression.

The question is​: is this desired (a.o.t. actual) behaviour\, or should

  use constant v1 => 1;

DWIM?

-- Johan

p5pRT commented 10 years ago

From @b2gills

On Tue\, Jan 7\, 2014 at 1​:21 AM\, Johan Vromans \jvromans@​squirrel\.nl wrote​:

Leon Timmermans \fawaka@​gmail\.com writes​:

use optionally takes a version\, so that is parsed as «use \ \ \»\, and => is not a valid start of an expression.

The question is​: is this desired (a.o.t. actual) behaviour\, or should

use constant v1 => 1;

DWIM?

I would expect that to be the equivalent to `use constant ('v1'\,1)` It is definitely being parsed as the version part of the `use` statement because it works if you place it in parens `use constant (v1 => 1)`

Although it makes it more difficult to create a v-string with a single element of ordinal 1.

  perl -MDevel​::Peek -E'use constant "v1" => 2;$v= v1;say Dump $v'

  perl -MDevel​::Peek -E'use constant "v1" => 2;$v= v01;say Dump $v'   perl -MDevel​::Peek -E'use constant "v1" => 2;$v= do{package clean;v1};say Dump $v'

So creating a subroutine matching `/\Av[0-9]+\z/` should probably be discouraged. Maybe even going so far as having `constant` warn if you ask it to create a constant with a matching name.

( Further discussion of having constant warn\, or adding a discouragement to the docs should be brought up in a new thread )

p5pRT commented 10 years ago

From @sciurius

Brad Gilbert \b2gills@​gmail\.com writes​:

I would expect that to be the equivalent to `use constant ('v1'\,1)`

Yes\, but the syntax of 'use' is (perdoc -f)​:

  use Module VERSION LIST

and not

  use Module VERSION \, LIST

(note the comma).

So in

  use Module X\,Y\,Z;

X\,Y\,Z is the LIST part\, even if X resembles a version number. The correct invocation for the latter is

  use Module X Y\,Z;

-- Johan

p5pRT commented 10 years ago

From @cpansprout

On Mon Jan 06 23​:21​:34 2014\, jv wrote​:

Leon Timmermans \fawaka@​gmail\.com writes​:

use optionally takes a version\, so that is parsed as «use \ \ \»\, and => is not a valid start of an expression.

The question is​: is this desired (a.o.t. actual) behaviour\, or should

use constant v1 => 1;

DWIM?

Probably\, especially considering that this dwims​:

use constant v1=> 1;

--

Father Chrysostomos

p5pRT commented 10 years ago

From @kentfredric

On 7 January 2014 22​:04\, Johan Vromans \jvromans@​squirrel\.nl wrote​:

Yes\, but the syntax of 'use' is (perdoc -f)​:

use Module VERSION LIST

and not

use Module VERSION \, LIST

(note the comma).

Indeed\, seems obvious given that criteria that

use Module 1\, 2; # Valid\, passes [ 1\, 2 ]

and

use Module 1 => 2; # Syntax error

it seems they'd aught to parse the same way. Just they don't.

  use v5.18;   use warnings;   use utf8;

  BEGIN {   package TestClass;

  our $VERSION = 9999;

  use Data​::Dump qw(pp);

  sub import {   my ( $self\, @​args ) = @​_;   pp \@​args;   1;   }   $INC{'TestClass.pm'} = 1;   }

  my @​code = (   q[use TestClass 1 => 2]\,   q[use TestClass v1 => 2]\,   q[use TestClass 1 2]\,   q[use TestClass v1 2]\,

  q[use TestClass 1\, 2]\,   q[use TestClass v1\, 2]\,

  q[use TestClass ( 1 => 2 )]\,   q[use TestClass ( v1 => 2 )]\,

  );

  for my $code ( @​code ) {   say '--';   say "$code";   eval $code or say $@​;   }

__[ output ]__

-- use TestClass 1 => 2 syntax error at (eval 1) line 1\, near "use TestClass 1 =>"

-- use TestClass v1 => 2 syntax error at (eval 2) line 1\, near "use TestClass v1 =>"

-- use TestClass 1 2 [2]

-- use TestClass v1 2 [2]

-- use TestClass 1\, 2 [1\, 2]

-- use TestClass v1\, 2 [v1\, 2]

-- use TestClass ( 1 => 2 ) [1\, 2]

-- use TestClass ( v1 => 2 ) ["v1"\, 2]

-- Kent \<http​://kent-fredric.fox.geek.nz>

p5pRT commented 10 years ago

From @b2gills

On Tue\, Jan 7\, 2014 at 3​:04 AM\, Johan Vromans \jvromans@&#8203;squirrel\.nl wrote​:

Brad Gilbert \b2gills@&#8203;gmail\.com writes​:

I would expect that to be the equivalent to `use constant ('v1'\,1)`

Yes\, but the syntax of 'use' is (perdoc -f)​:

use Module VERSION LIST

and not

use Module VERSION \, LIST

(note the comma).

So in

use Module X\,Y\,Z;

X\,Y\,Z is the LIST part\, even if X resembles a version number. The correct invocation for the latter is

use Module X Y\,Z;

I said it is being parsed as the version part\, not that is what I expected. What I meant was that I expected it to be essentially the same as​:

  use constant; sub v1(){1}

That is I would have expected it to be parsed as the first item in the list\, not the minimum version.

Which is why I also said it would make it difficult to create a v-string with a single element of ordinal 1.

p5pRT commented 10 years ago

From @rjbs

I agree with the general consensus that this is a bug.

-- rjbs

p5pRT commented 10 years ago

From [Unknown Contact. See original ticket]

I agree with the general consensus that this is a bug.

-- rjbs