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

Calling .substr with a Callable for $from that creates a Rat dies #1717

Closed
MasterDuke17 opened this issue Apr 9, 2018 · 0 comments
Closed
Assignees

Comments

@MasterDuke17
Copy link
Contributor

The Problem

[21:29] <colomon> p6: say “5134”.substr(0, */2)
[21:29] <+camelia> rakudo-moar 404f30217: OUTPUT: «This type cannot unbox to a native integer: P6opaque, Rat␤  in block <unit> at <tmp> line 1␤␤»
[21:29] <colomon> p6: say “5134”.substr(0, * div 2)
[21:29] <+camelia> rakudo-moar 404f30217: OUTPUT: «51␤»
[21:34] <colomon> documentation ( https://docs.perl6.org/routine/substr ) seems off, plus requiring an Int instead of a Rat seems needlessly picky

.substr can take a Callable for several of its parameters, but */2 dies, while * div 2 is ok.

Expected Behavior

If Rats should be allowed, then say “5134”.substr(0, */2) should output "51".

For these multis for .substr https://github.com/rakudo/rakudo/blob/master/src/core/Str.pm6#L2719-L2762,
a potential fix is converting lines like this my int $from = (start)(nqp::chars($!value)) to my int $from = ((start)(nqp::chars($!value))).Int. I tried this and it correctly fixed calling with */2, but I didn't run a spectest.

Actual Behavior

Dies with This type cannot unbox to a native integer: P6opaque, Rat in block <unit> at -e line 1

Steps to Reproduce

perl6 -e 'say “5134”.substr(*/2)'

Environment

  • Operating system: Kubuntu 17.10 Linux hermes 4.13.0-37-generic #42-Ubuntu SMP Wed Mar 7 14:13:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Compiler version (perl6 -v): This is Rakudo version 2018.03-206-g0a08f1d0a built on MoarVM version 2018.03-99-g4234ab56b
@zoffixznet zoffixznet self-assigned this Apr 9, 2018
zoffixznet added a commit that referenced this issue Apr 9, 2018
Fixes R#1717 #1717

- When Range is given, coerce the endpoints to Int
- When Callable is given, coerce its return value to Int
- When (Non-Int, Callable) are used, fix crash due to attempt to
    numerically compare Callable with Inf
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

2 participants