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

comma (wrongly) required between parameter with default value and returns-arrow ('-->') in Rakudo #3141

Closed
p6rt opened this issue May 20, 2013 · 7 comments

Comments

@p6rt
Copy link

p6rt commented May 20, 2013

Migrated from rt.perl.org#118063 (status was 'resolved')

Searchable as RT118063$

@p6rt
Copy link
Author

p6rt commented Jun 28, 2012

From gerd.r.devel@googlemail.com

<not_gerd> rn​: sub ($ = 42 --> Int) { ... }
<p6eval> niecza v19-4-g12b71c7​: ( no output )
<p6eval> ..rakudo 88a9d6​: OUTPUT«===SORRY!===␤Missing block␤at
/tmp/rjG5cSGHkE​:1␤»

@p6rt
Copy link
Author

p6rt commented Sep 9, 2012

From @ronaldxs

On Thu Jun 28 01​:11​:14 2012, gerd.r.devel@​googlemail.com wrote​:

<not_gerd> rn​: sub ($ = 42 --> Int) { ... }
<p6eval> niecza v19-4-g12b71c7​: ( no output )
<p6eval> ..rakudo 88a9d6​: OUTPUT«===SORRY!===␤Missing block␤at
/tmp/rjG5cSGHkE​:1␤»

I ran into this with a named subroutine but noticed there that the
prefix form of declaring the return type seems to be effective as a
workaround.

So

sub foo(Int $x = 3 --> Rat) { return $x / 2}

unsurprisingly gives the same error but

my/our Rat sub foo(Int $x = 3) { return $x / 2}

seems to work as expected.

@p6rt
Copy link
Author

p6rt commented Sep 9, 2012

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

@p6rt
Copy link
Author

p6rt commented May 20, 2013

From @masak

<lizmat> r​: sub a ( $a=1, --> Hash ) { say $a; my %h }; say a(2)
<camelia> rakudo 8d2ec9​: OUTPUT«2␤().hash␤»
<lizmat> r​: sub a ( $a=1 --> Hash ) { say $a; my %h }; say a(2)
<camelia> rakudo 8d2ec9​: OUTPUT«===SORRY!===␤Missing block␤at
/tmp/NxD226NWlT​:1␤------> sub a ( $a=1 --> Hash ⏏) { say $a; my %h };
say a(2)␤ expecting any of​:␤ postfix␤ infix stopper␤
  infix or meta-infix␤ prefix or term␤ …
<lizmat> for some reason, if we have a default, we need a comma there
<lizmat> r​: sub a ( $a --> Hash ) { say $a; my %h }; say a(2)
<camelia> rakudo 8d2ec9​: OUTPUT«2␤().hash␤»
* masak submits rakudobug for the required comma

I have a feeling I know what's up. The default puts the parser in EXPR
mode. The '-->' should be a stopper, but it isn't, so it gets parsed
as '- ->', binary minus and a pointy. The Hash gets gobbled up as a
parameter, and then the parser expects a block, not ')'. This is
consistent with the error message.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

This works now without the comma​:

$ perl6-m -e 'sub a ( $a=1 --> Hash ) { say $a; my %h }; say a(2)'
2

^^ empty string here ;-)

I added a test to S06-signature/defaults.t with the following commit​: Raku/roast@4485db4547

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

This works now without the comma​:

$ perl6-m -e 'sub a ( $a=1 --> Hash ) { say $a; my %h }; say a(2)'
2

^^ empty string here ;-)

I added a test to S06-signature/defaults.t with the following commit​: Raku/roast@4485db4547

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

@usev6 - Status changed from 'new' to 'resolved'

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

1 participant