Skip Menu |
Report information
Id: 129100
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: cookbook_000 [at] yahoo.co.jp <titsuki [at] cpan.org>
Cc:
AdminCc:

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



Subject: [BUG] method rand (Range) fails to check type of $!max
Download (untitled) / with headers
text/plain 363b
See the following results. $ perl6 -e '("10"..15).rand.say' # min is Str Can only get a random value on Real values, did you mean .pick? in block <unit> at -e line 1 Actually thrown at: in block <unit> at -e line 1 $ perl6 -e '(10.."15").rand.say' # max is Str 13.1798515362137 I think that the 2nd example should cause the error same as the 1st example.
Download (untitled) / with headers
text/plain 616b
Sorry, my Perl 6 version is $ perl6 --version This is Rakudo version 2016.07.1-199-gdd9b760 built on MoarVM version 2016.07-17-g40948f6 implementing Perl 6.c. On 2016-8月-26 金 19:23:02, cookbook_000@yahoo.co.jp wrote: Show quoted text
> See the following results. > > $ perl6 -e '("10"..15).rand.say' # min is Str > Can only get a random value on Real values, did you mean .pick? > in block <unit> at -e line 1 > > Actually thrown at: > in block <unit> at -e line 1 > > $ perl6 -e '(10.."15").rand.say' # max is Str > 13.1798515362137 > > > I think that the 2nd example should cause the error same as the 1st example.
Download (untitled) / with headers
text/plain 539b
I've sent a pull request for this issue. https://github.com/rakudo/rakudo/pull/863 On 2016-8月-26 金 19:23:02, cookbook_000@yahoo.co.jp wrote: Show quoted text
> See the following results. > > $ perl6 -e '("10"..15).rand.say' # min is Str > Can only get a random value on Real values, did you mean .pick? > in block <unit> at -e line 1 > > Actually thrown at: > in block <unit> at -e line 1 > > $ perl6 -e '(10.."15").rand.say' # max is Str > 13.1798515362137 > > > I think that the 2nd example should cause the error same as the 1st example.
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 531b
The issue is due to there being a multi new [^1] that takes a Real min value and *coerces* the max value to a real. So in the case described in this ticket, it will coerce the Str max to Int, and by the time we get to .rand, both args are Ints. As suggested on IRC [^2], we can try removing that coercion and see if something explodes or not, but I'm unsure of the reasons that coercion is there. [^1] https://github.com/rakudo/rakudo/blob/aceb4af2/src/core/Range.pm#L51 [^2] http://irclog.perlgeek.de/perl6/2016-09-04#i_13145737


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