You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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. :-(
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
The text was updated successfully, but these errors were encountered: