Skip Menu |
Report information
Id: 125670
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: gjb [at] google.com
Cc:
AdminCc:

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



To: rakudobug [...] perl.org
Subject: Can't set rx{} as parameter default
From: Geoffrey Broadwell <gjb [...] google.com>
Date: Thu, 23 Jul 2015 19:09:42 -0700
Download (untitled) / with headers
text/plain 679b
It appears you can't use an rx{} literal as a parameter default:
$ perl6 -e 'sub foo($r) { say $r }; foo(rx{bar});'
rx{bar}
$ perl6 -e 'sub foo($r = rx{foo}) { say $r }; foo(rx{bar});'
===SORRY!===
Cannot call method 'match' on a null object
$ perl6 -v
This is perl6 version 2015.06-314-g5d1ec3c built on MoarVM version 2015.06-98-gf22142b
This is golfed down from a bug causing flussence's Text-Tabs-Wrap module Text::Wrap to no longer compile, throwing the above SORRY! error right when it tries to parse the params to sub wrap().
Interestingly there appears to be a funky workaround:
$ perl6 -e 'sub foo($r = {rx{foo}}()) { say $r }; foo(rx{bar}); foo();'
rx{bar}
rx{foo}

Download (untitled) / with headers
text/plain 876b
On Thu Jul 23 19:11:18 2015, gjb@google.com wrote: Show quoted text
> It appears you can't use an rx{} literal as a parameter default: > > $ perl6 -e 'sub foo($r) { say $r }; foo(rx{bar});' > rx{bar} > $ perl6 -e 'sub foo($r = rx{foo}) { say $r }; foo(rx{bar});' > ===SORRY!=== > Cannot call method 'match' on a null object > $ perl6 -v > This is perl6 version 2015.06-314-g5d1ec3c built on MoarVM version > 2015.06-98-gf22142b > > This is golfed down from a bug causing flussence's Text-Tabs-Wrap > module Text::Wrap to no longer compile, throwing the above SORRY! > error right when it tries to parse the params to sub wrap(). > > Interestingly there appears to be a funky workaround: > > $ perl6 -e 'sub foo($r = {rx{foo}}()) { say $r }; foo(rx{bar}); foo();' > rx{bar} > rx{foo}
Turned out to be a funky "static analysis gone wild" bug. Fixed, added test in S06-signature/defaults.t.


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