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

Owner: Nobody
Requestors: ceronman [at] gmail.com
Cc:
AdminCc:

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



Subject: Function "one" may not be called without arguments
Date: Sun, 10 Jan 2016 22:22:34 +0100
From: Manuel Cerón <ceronman [...] gmail.com>
To: rakudobug [...] perl.org
The following error seems to be a bug:

$ perl6 -e 'sub one { 1 }; say one;'
===SORRY!=== Error while compiling -e
Function "one" may not be called without arguments (please use () or whitespace to denote arguments)
at -e:1
------> sub one { 1 }; say one⏏;

My setup:

$ perl6 --version
This is perl6 version 2015.06 built on MoarVM version 2015.06
OS X 10.10.5

The discussion on #perl6 about it:

[21:55] <ceronman> Hi everyone, I just installed Perl 6 on OS X (via brew install rakudo-star). I'm just trying the language.
[21:55] <ceronman> while playing with it, I ran into an error when running this: perl6 -e 'sub one { 1 }; one;'
[21:56] <ceronman> why is the error happening? it seems the name 'one' is colliding with something as it doesn't happen with other function names
[21:56] <BenGoldberg> m: say one;
[21:56] <+camelia> rakudo-moar 9f64ce: OUTPUT«===SORRY!=== Error while compiling /tmp/U9LOJjZO5d␤Function "one" may not be called without arguments (please use () or whitespace to denote arguments, or &one to refer to the function as a noun)␤at /tmp/U9LOJjZO5d:1␤------> say one⏏;␤»
[21:56] <BenGoldberg> m: sub one { 42 }; one;
[21:56] <+camelia> rakudo-moar 9f64ce: OUTPUT«===SORRY!=== Error while compiling /tmp/pTc51hLMH3␤Function "one" may not be called without arguments (please use () or whitespace to denote arguments, or &one to refer to the function as a noun)␤at /tmp/pTc51hLMH3:1␤------> sub one { 42 }; o…»
[21:56] <BenGoldberg> m: sub one { 42 }; one();
[21:56] <+camelia> rakudo-moar 9f64ce: ( no output )
[21:57] <BenGoldberg> m: sub one { 42 }; say one.WHAT;
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«===SORRY!=== Error while compiling /tmp/MHO9dMTX6S␤Function "one" may not be called without arguments (please use () or whitespace to denote arguments, or &one to refer to the function as a noun)␤at /tmp/MHO9dMTX6S:1␤------> sub one { 42 }; s…»
[21:57] <BenGoldberg> m: sub one { 42 }; say &one.WHAT;
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«(Sub)␤»
[21:57] <BenGoldberg> m: sub one { 42 }; say &one.perl;
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«sub one () { #`(Sub|81598528) ... }␤»
[21:57] <BenGoldberg> m: say &one.perl;
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«sub one (+ is raw) { #`(Sub+{<anon|49450304>}|67143056) ... }␤»
[21:57] <BenGoldberg> m: my $foo; one($foo);
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«WARNINGS for /tmp/7WEXfjzD9B:␤Useless use of "one($foo)" in expression "one($foo)" in sink context (line 1)␤»
[21:57] <BenGoldberg> m: my $foo; say one($foo);
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«one((Any))␤»
[21:57] <BenGoldberg> m: my $foo; say one($foo); say $foo
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«one((Any))␤(Any)␤»
[21:57] <BenGoldberg> m: my $foo = ; say one($foo); say $foo
[21:57] <+camelia> rakudo-moar 9f64ce: OUTPUT«===SORRY!=== Error while compiling /tmp/A0DGNFryKu␤Malformed initializer␤at /tmp/A0DGNFryKu:1␤------> my $foo =⏏ ; say one($foo); say $foo␤    expecting any of:␤        prefix␤        term␤»
[21:58] <BenGoldberg> m: my $foo = 1; say one($foo); say $foo; # stupid fingers
[21:58] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(1)␤1␤»
[21:58] <BenGoldberg> m: my $foo = 2; say one($foo); say $foo;
[21:58] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(2)␤2␤»
[21:58] <BenGoldberg> m: my $foo = 2; say one($foo++); say $foo;
[21:58] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(2)␤3␤»
[21:58] <BenGoldberg> m: my $foo = 2; say one(1); say $foo;
[21:58] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(1)␤2␤»
[21:58] <BenGoldberg> m: say one('what does this button do');
[21:59] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(what does this button do)␤»
[21:59] <lizmat> m: dd one(True,False,False), one(True,True,False)   # ceronman
[21:59] <+camelia> rakudo-moar 9f64ce: OUTPUT«Method 'name' not found for invocant of class 'Bool'␤  in any  at gen/moar/m-Metamodel.nqp line 3124␤  in block <unit> at /tmp/hIMatcxyJm line 1␤␤»
[21:59] <lizmat> hmmm...
[21:59] <lizmat> m: say one(True,False,False), one(True,True,False)
[21:59] <+camelia> rakudo-moar 9f64ce: OUTPUT«one(True, False, False)one(True, True, False)␤»
[22:00] <lizmat> m: say so one(True,False,False), so one(True,True,False)
[22:00] <+camelia> rakudo-moar 9f64ce: OUTPUT«TrueFalse␤»
[22:00] <BenGoldberg> m: say one(1).WHAT;
[22:00] <+camelia> rakudo-moar 9f64ce: OUTPUT«(Junction)␤»
[22:00] <lizmat> one() creates a junction that yields True if only one of the values is True
[22:01] <ceronman> I understand that, but then why if I define my own 'one' function, I get that error?
[22:01] <BenGoldberg> Add parens.
[22:02] <ceronman> ok, if I type the parens, I don't get the error, but why do I get it without the parens?
[22:05] <lizmat> OTOH, one is just a sub in the setting... hmmm...
[22:06] <ceronman> lizmat: it looks like a bug. It doesn't happen with other names, even if they collide with thigs: perl6 -e 'sub elems { 1 }; say elems;'
[22:12] <lizmat> ceronman: indeed, could you please report this rakudobug@perl.org and quote the conversation here ?
[22:13] <ceronman> lizmat: I will thanks for the help
Subject: [BUG] Built-ins `all, any, one, none` clobber zero-arg functions with same name in user scope
Download (untitled) / with headers
text/plain 649b
It doesn't only happen with &one, but with all the Junction-constructing subroutines. For example with &all: ➜ sub all { 1 }; say all; ===SORRY!=== Error while compiling -e Function "all" may not be called without arguments (please use () or whitespace to denote arguments, or &all to refer to the function as a noun) It may have to do with their signature (as reported by the `.signature` introspection method): sub all (+ is raw) sub any (+ is raw) sub one (+ is raw) sub none (+ is raw) However, the subroutine &list has the same signature, and does not suffer from this issue: sub list (+ is raw)
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 520b
On Tue, 10 May 2016 14:27:20 -0700, smls75@gmail.com wrote: Show quoted text
> It may have to do with their signature (as reported by the > `.signature` introspection method):
They're actually special-cased in the grammar[^1] based on their name: https://github.com/rakudo/rakudo/blob/4570238de7260b7360333aa216bb2b56949018fa/src/Perl6/Grammar.nqp#L3266-L3272 If it's possible to determine whether the name belongs to a non-core routine at the point where the error is emitted in the grammar, that'd be one way of avoiding the issue.


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