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

no-args function call broken for some names #4870

Open
p6rt opened this issue Dec 14, 2015 · 4 comments
Open

no-args function call broken for some names #4870

p6rt opened this issue Dec 14, 2015 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 14, 2015

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

Searchable as RT126909$

@p6rt
Copy link
Author

p6rt commented Dec 14, 2015

From zefram@fysh.org

Normally a sub that accepts an empty argument list can be called with
or without parens​:

sub hat () { say "You can keep your hat on" }
sub hat () { #`(Sub|95476664) ... }
hat()
You can keep your hat on
hat
You can keep your hat on

But this doesn't work if the sub has one of 35 magic names​:

sub bag () { say "Papa's got a brand new bag" }
sub bag () { #`(Sub|95476816) ... }
bag()
Papa's got a brand new bag
bag
===SORRY!===
Argument to "bag" seems to be malformed
at <unknown file>​:1
------> bag^<EOL>
Other potential difficulties​:
  Function "bag" may not be called without arguments (please use () or whitespace to denote arguments, or &bag to refer to the function as a noun)
  at <unknown file>​:1
  ------> bag^<EOL>

This is not an intrinsic feature of the sub; it's tied to the name used
at the call site​:

my &WBAG := &bag
sub bag () { #`(Sub|101248400) ... }
&WBAG
sub bag () { #`(Sub|101248400) ... }
WBAG()
Papa's got a brand new bag
WBAG
Papa's got a brand new bag
my &WHAT := &hat
sub hat () { #`(Sub|101248552) ... }
&WHAT
sub hat () { #`(Sub|101248552) ... }
WHAT()
You can keep your hat on
WHAT
===SORRY!===
Argument to "WHAT" seems to be malformed
at <unknown file>​:1
------> WHAT^<EOL>
Other potential difficulties​:
  Function "WHAT" may not be called without arguments (please use () or whitespace to denote arguments, or &WHAT to refer to the function as a noun)
  at <unknown file>​:1
  ------> WHAT^<EOL>

The cause of this behaviour is some magic in Perl6/Grammar.nqp that
specially recognises certain names at parse time. It's intended to
affect calls to certain built-in subs, and I'm not objecting to such
magic being applied to calls to those subs. The bug is that the magic
gets applied to calls to unrelated user-defined subs, based purely on a
coincidence of names. Conversely, the intended magic is not applied to
calls to subs that should get it, if the call happens to be made through
a non-magical name​:

my &disjunction := &any
sub any (+ is raw) { #`(Sub+{<anon|77550672>}|76300224) ... }
disjunction()
any()
disjunction
any()
any()
any()
any
===SORRY!===
Argument to "any" seems to be malformed
at <unknown file>​:1
------> any^<EOL>
Other potential difficulties​:
  Function "any" may not be called without arguments (please use () or whitespace to denote arguments, or &any to refer to the function as a noun)
  at <unknown file>​:1
  ------> any^<EOL>

This magic should not be triggered by the name. It should be triggered
by a flag attached to the Sub object. Ideally the flag should be a
trait that anyone can set on their own subs. And the magic should
be documented.

-zefram

@p6rt
Copy link
Author

p6rt commented Dec 15, 2015

From 1parrota@gmail.com

If someone is using the name of language features for subroutines,
wouldn't it be better at least to issue a warning of some sort? That's
prima facie evidence they simply don't know about the feature.

@p6rt
Copy link
Author

p6rt commented Dec 15, 2015

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

@p6rt
Copy link
Author

p6rt commented Dec 16, 2015

From zefram@fysh.org

Parrot Raiser via RT wrote​:

prima facie evidence they simply don't know about the feature.

Or that they do know about the name scoping features.

-zefram

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant