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

Built-ins `all, any, one, none` clobber user-defined zero-arg functions with same name #5036

Open
p6rt opened this issue Jan 10, 2016 · 4 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Jan 10, 2016

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

Searchable as RT127235$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jan 10, 2016

From ceronman@gmail.com

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

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented May 10, 2016

From @smls

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)

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jan 13, 2017

From @zoffixznet

On Tue, 10 May 2016 14​:27​:20 -0700, smls75@​gmail.com wrote​:

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.

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jan 13, 2017

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

@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
Projects
None yet
1 participant
You can’t perform that action at this time.