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

method rand (Range) fails to check type of $!max #5619

Open
p6rt opened this issue Aug 27, 2016 · 5 comments
Open

method rand (Range) fails to check type of $!max #5619

p6rt opened this issue Aug 27, 2016 · 5 comments
Labels
Bug

Comments

@p6rt
Copy link

@p6rt p6rt commented Aug 27, 2016

Migrated from rt.perl.org#129100 (status was 'new')

Searchable as RT129100$

@p6rt
Copy link
Author

@p6rt p6rt commented Aug 27, 2016

From @titsuki

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.

@p6rt
Copy link
Author

@p6rt p6rt commented Aug 27, 2016

From @titsuki

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​:

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.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 4, 2016

From @titsuki

I've sent a pull request for this issue.
rakudo/rakudo#863

On 2016-8月-26 金 19​:23​:02, cookbook_000@​yahoo.co.jp wrote​:

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.

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 4, 2016

From @zoffixznet

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

1 similar comment
@p6rt
Copy link
Author

@p6rt p6rt commented Sep 4, 2016

From @zoffixznet

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

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.