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
[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
The text was updated successfully, but these errors were encountered:
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
The Problem
.substr can take a Callable for several of its parameters, but
*/2dies, while* div 2is 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))tomy 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 1Steps to Reproduce
perl6 -e 'say “5134”.substr(*/2)'Environment
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/Linuxperl6 -v):This is Rakudo version 2018.03-206-g0a08f1d0a built on MoarVM version 2018.03-99-g4234ab56bThe text was updated successfully, but these errors were encountered: