Skip Menu |
Report information
Id: 126909
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: zefram [at] fysh.org
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



To: rakudobug [...] perl.org
From: Zefram <zefram [...] fysh.org>
Date: Mon, 14 Dec 2015 01:45:36 +0000
Subject: [BUG] no-args function call broken for some names
Download (untitled) / with headers
text/plain 2.6k
Normally a sub that accepts an empty argument list can be called with or without parens: Show quoted text
> sub hat () { say "You can keep your hat on" }
sub hat () { #`(Sub|95476664) ... } Show quoted text
> hat()
You can keep your hat on Show quoted text
> hat
You can keep your hat on But this doesn't work if the sub has one of 35 magic names: Show quoted text
> sub bag () { say "Papa's got a brand new bag" }
sub bag () { #`(Sub|95476816) ... } Show quoted text
> bag()
Papa's got a brand new bag Show quoted text
> 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: Show quoted text
> my &WBAG := &bag
sub bag () { #`(Sub|101248400) ... } Show quoted text
> &WBAG
sub bag () { #`(Sub|101248400) ... } Show quoted text
> WBAG()
Papa's got a brand new bag Show quoted text
> WBAG
Papa's got a brand new bag Show quoted text
> my &WHAT := &hat
sub hat () { #`(Sub|101248552) ... } Show quoted text
> &WHAT
sub hat () { #`(Sub|101248552) ... } Show quoted text
> WHAT()
You can keep your hat on Show quoted text
> 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: Show quoted text
> my &disjunction := &any
sub any (+ is raw) { #`(Sub+{<anon|77550672>}|76300224) ... } Show quoted text
> disjunction()
any() Show quoted text
> disjunction
any() Show quoted text
> any()
any() Show quoted text
> 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
From: Parrot Raiser <1parrota [...] gmail.com>
To: perl6-compiler [...] perl.org
Subject: Re: [perl #126909] [BUG] no-args function call broken for some names
Date: Tue, 15 Dec 2015 10:44:16 -0500
Download (untitled) / with headers
text/plain 202b
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.
Subject: Re: [perl #126909] [BUG] no-args function call broken for some names
Date: Tue, 15 Dec 2015 23:04:31 +0000
To: Parrot Raiser via RT <perl6-bugs-followup [...] perl.org>
From: Zefram <zefram [...] fysh.org>
Download (untitled) / with headers
text/plain 157b
Parrot Raiser via RT wrote: Show quoted text
>prima facie evidence they simply don't know about the feature.
Or that they do know about the name scoping features. -zefram


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org