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

Kavorka signature bug #32

Open
tobyink opened this issue Jan 9, 2021 · 1 comment
Open

Kavorka signature bug #32

tobyink opened this issue Jan 9, 2021 · 1 comment

Comments

@tobyink
Copy link
Owner

tobyink commented Jan 9, 2021

Migrated from rt.cpan.org #97782 (status was 'open')

Requestors:

From [email protected] on 2014-08-06 14:52:06
:

The following code fails on Kavorka-0.030 (the latest at this time):
use v5.14;use Kavorka;
fun test(Num $a, :$b = 1 --> Num ){}
The error message is
Can't modify constant item in postdecrement (--) at test.pl line 4, near "1 --"
It works without the return type.
I am using perl 5.20 on Linux debian 3.2.0-4-686-pae #1 SMP Debian 3.2.60-1+deb7u1 i686 GNU/Linux

@tobyink
Copy link
Owner Author

tobyink commented Jan 9, 2021

From [email protected] on 2014-08-07 09:11:16
:

The "--" part is taken to be a post-decrement operator on the "1".

When you supply a default value for a parameter, you can use operators in that default; e.g.

fun blah ($a=1, $b=2+2) { ... }

The expression is parsed as an "arithexpr". If you look at the list of operators under "Operator Precedence and Associativity" in perlop, that's everything up to and including the bitshift operators "<<" and ">>".

An arithexpr needs to be terminated by something like a comma or a closing bracketing character. So a workaround could be something like:

fun test(Num $a, :$b = 1, ... --> Num ){}

This means you sacrifice argument count checking though. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant