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

[PATCH] perlop: words before a fat arrow comma can start with - #16855

Open
p5pRT opened this issue Mar 1, 2019 · 7 comments
Open

[PATCH] perlop: words before a fat arrow comma can start with - #16855

p5pRT opened this issue Mar 1, 2019 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 1, 2019

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

Searchable as RT133873$

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2019

From dot@dotat.at

This is a bug report for perl from dot@​dotat.at,
generated with the help of perlbug 1.41 running under perl 5.29.9.


I was checking whether '-' is allowed inside barewords before
fat arrows, as well as at the start of the bareword, and I
saw that perlop does not mention that '-' is allowed at the
start. Well, it is mentioned as a special case for unary minus,
but the description of '=>' says it ignores precedence which
suggests that the unary minus special case doesn't apply. And
in toke.c there is another special case for '-bareword =>' which
implies to me that this should be mentioned in the docs for '=>'.



Flags​:
  category=docs
  severity=low
  Type=Patch
  PatchStatus=HasPatch


Site configuration information for perl 5.29.9​:

Configured by fanf2 at Fri Mar 1 16​:47​:41 GMT 2019.

Summary of my perl5 (revision 5 version 29 subversion 9) configuration​:
  Local Commit​: ab9c75bb9b8c06b34fb988bdd5170b0976b38cbb
  Ancestor​: de59f38
  Platform​:
  osname=linux
  osvers=4.9.0-8-amd64
  archname=x86_64-linux
  uname='linux grey.csi.cam.ac.uk 4.9.0-8-amd64 #1 smp debian 4.9.130-2 (2018-10-27) x86_64 gnulinux '
  config_args='-des -Dusedevel'
  hint=recommended
  useposix=true
  d_sigaction=define
  useithreads=undef
  usemultiplicity=undef
  use64bitint=define
  use64bitall=define
  uselongdouble=undef
  usemymalloc=n
  default_inc_excludes_dot=define
  bincompat5005=undef
  Compiler​:
  cc='cc'
  ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
  optimize='-O2'
  cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
  ccversion=''
  gccversion='6.3.0 20170516'
  gccosandvers=''
  intsize=4
  longsize=8
  ptrsize=8
  doublesize=8
  byteorder=12345678
  doublekind=3
  d_longlong=define
  longlongsize=8
  d_longdbl=define
  longdblsize=16
  longdblkind=3
  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-strong -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/6/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
  libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
  perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
  libc=libc-2.24.so
  so=so
  useshrplib=false
  libperl=libperl.a
  gnulibc_version='2.24'
  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-strong'

Locally applied patches​:
  ab9c75bb9b8c06b34fb988bdd5170b0976b38cbb


@​INC for perl 5.29.9​:
  lib
  /usr/local/lib/perl5/site_perl/5.29.9/x86_64-linux
  /usr/local/lib/perl5/site_perl/5.29.9
  /usr/local/lib/perl5/5.29.9/x86_64-linux
  /usr/local/lib/perl5/5.29.9


Environment for perl 5.29.9​:
  HOME=/home/fanf2
  LANG (unset)
  LANGUAGE (unset)
  LC_CTYPE=C.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/home/fanf2/bin​:/home/fanf2/gnu/bin​:/opt/bind/bin​:/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/usr/games​:/sbin​:/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 1, 2019

From dot@dotat.at

0001-perlop-words-before-a-fat-arrow-comma-can-start-with.patch
From ab9c75bb9b8c06b34fb988bdd5170b0976b38cbb Mon Sep 17 00:00:00 2001
Message-Id: <ab9c75bb9b8c06b34fb988bdd5170b0976b38cbb.1551458815.git.dot@dotat.at>
From: Tony Finch <dot@dotat.at>
Date: Fri, 1 Mar 2019 16:42:12 +0000
Subject: [PATCH] perlop: words before a fat arrow comma can start with -

---
 pod/perlop.pod | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pod/perlop.pod b/pod/perlop.pod
index af695b678f..5b6c391b5d 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -1250,7 +1250,7 @@ from left to right.
 The C<< => >> operator (sometimes pronounced "fat comma") is a synonym
 for the comma except that it causes a
 word on its left to be interpreted as a string if it begins with a letter
-or underscore and is composed only of letters, digits and underscores.
+or underscore or minus and is composed only of letters, digits and underscores.
 This includes operands that might otherwise be interpreted as operators,
 constants, single number v-strings or function calls.  If in doubt about
 this behavior, the left operand can be quoted explicitly.
-- 
2.18.0

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2019

From @jkeenan

On Fri, 01 Mar 2019 17​:39​:21 GMT, dot@​dotat.at wrote​:

This is a bug report for perl from dot@​dotat.at,
generated with the help of perlbug 1.41 running under perl 5.29.9.

-----------------------------------------------------------------

I was checking whether '-' is allowed inside barewords before
fat arrows, as well as at the start of the bareword, and I
saw that perlop does not mention that '-' is allowed at the
start. Well, it is mentioned as a special case for unary minus,
but the description of '=>' says it ignores precedence which
suggests that the unary minus special case doesn't apply. And
in toke.c there is another special case for '-bareword =>' which
implies to me that this should be mentioned in the docs for '=>'.

Could you prepare a patch (probably in pod/perlop.pod) for the change of documentation you would like to see?

(Patches are best prepared in a git checkout of the Perl 5 respository, using 'git format-patch'. However, 'patch' and 'diff' also can be used.)

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2019

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

@p5pRT
Copy link
Author

p5pRT commented Mar 3, 2019

From @tonycoz

On Fri, 01 Mar 2019 09​:39​:21 -0800, dot@​dotat.at wrote​:

I was checking whether '-' is allowed inside barewords before
fat arrows, as well as at the start of the bareword, and I
saw that perlop does not mention that '-' is allowed at the
start. Well, it is mentioned as a special case for unary minus,
but the description of '=>' says it ignores precedence which
suggests that the unary minus special case doesn't apply. And
in toke.c there is another special case for '-bareword =>' which
implies to me that this should be mentioned in the docs for '=>'.

The - isn't part of the bareword, the -foo => ... results in the unary negation operator being applied to the foo bareword​:

tony@​mars​:.../git/perl$ ./perl -Dt -e '-foo => 1'
(-e​:1) const(PV("foo"\0))
(-e​:1) negate

EXECUTING...

(-e​:0) enter
(-e​:0) nextstate
(-e​:1) leave

This is documented in perlop​:

Unary C<"-"> performs arithmetic negation if the operand is numeric,
including any string that looks like a number. If the operand is
an identifier, a string consisting of a minus sign concatenated
with the identifier is returned. Otherwise, if the string starts
with a plus or minus, a string starting with the opposite sign is
returned. One effect of these rules is that C<-bareword> is equivalent
to the string C<"-bareword">. If, however, the string begins with a
non-alphabetic character (excluding C<"+"> or C<"-">), Perl will attempt
to convert
the string to a numeric, and the arithmetic negation is performed. If the
string cannot be cleanly converted to a numeric, Perl will give the warning
B<Argument "the string" isn't numeric in negation (-) at ...>.
X<-> X<negation, arithmetic>

Tony

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2019

From dot@dotat.at

On 3 Mar 2019, at 00​:17, James E Keenan via RT <perlbug-followup@​perl.org> wrote​:

Could you prepare a patch (probably in pod/perlop.pod) for the change of documentation you would like to see?

Yep, done, and attached to the report using perlbug as described in https://perldoc.perl.org/perlhack.html#PATCHING-PERL

Tony.
--
f.anthony.n.finch <dot@​dotat.at> http​://dotat.at

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2019

From dot@dotat.at

On 3 Mar 2019, at 01​:29, Tony Cook via RT <perlbug-followup@​perl.org> wrote​:

The - isn't part of the bareword, the -foo => ... results in the unary negation operator being applied to the foo bareword​:

Yep, that’s kind of right, and I explained that in my bug report, but the documentation is still incomplete and confusing and does not match the special case for -bareword=> in toke.c. See https://perl5.git.perl.org/perl.git/blob/HEAD:/toke.c#l5666for the code that implements the special case for - before a bareword before =>

This code overrides the bit of the documentation which says barewords before => override all operator precedence. See https://perl5.git.perl.org/perl.git/blob/HEAD:/pod/perlop.pod#l1280

So if I am looking up the syntax for what appears before => in the current docs I need to know that “bareword” is jargon for “interpreted as a string” (but the explanation of => does not mention “bareword”) and I need to know that the explanation for how the - operator works on barewords is not just a property of the operator, but also a property of the lexical syntax that has an undocumented special case before =>

Tony.
--
f.anthony.n.finch <dot@​dotat.at> http​://dotat.at

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

3 participants