Skip to content

Commit

Permalink
Fix poor error with infix:<xx> with non-numeric Str
Browse files Browse the repository at this point in the history
When '123aaa' is given, the Failure occurs inside the coercion,
which we then attempt to store in a native int, triggering a bad error

Fix by moving the coercer into the Num() multi, where such a Failure
would explode in the .Int method.

Fixes RT#130288: https://rt.perl.org/Ticket/Display.html?id=130288

P.S: this is probably a deeper issue with our coercers; IIRC there's
a ticket that they don't check the final type.
  • Loading branch information
zoffixznet committed Dec 7, 2016
1 parent b2ac4e4 commit 5bacb05
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/List.pm
Expand Up @@ -1347,7 +1347,7 @@ role XX-Whatever does Iterator {
proto sub infix:<xx>(|) { * }
multi sub infix:<xx>() { Failure.new("No zero-arg meaning for infix:<xx>") }
multi sub infix:<xx>(Mu \x) { x }
multi sub infix:<xx>(&x, Num $n) {
multi sub infix:<xx>(&x, Num() $n) {
infix:<xx>(&x, $n == Inf ?? Whatever !! $n.Int);
}
multi sub infix:<xx>(&x, Whatever) {
Expand All @@ -1370,7 +1370,7 @@ multi sub infix:<xx>(&x, Whatever) {
}
}.new(&x))
}
multi sub infix:<xx>(&x, Int() $n) {
multi sub infix:<xx>(&x, Int $n) {
my int $todo = $n + 1;
my Mu $pulled;
my Mu $list := nqp::list();
Expand All @@ -1388,15 +1388,15 @@ multi sub infix:<xx>(&x, Int() $n) {
);
nqp::p6bindattrinvres(nqp::create(List), List, '$!reified', $list)
}
multi sub infix:<xx>(Mu \x, Num $n) {
multi sub infix:<xx>(Mu \x, Num() $n) {
infix:<xx>(x, $n == Inf ?? Whatever !! $n.Int);
}
multi sub infix:<xx>(Mu \x, Whatever) {
Seq.new(class :: does XX-Whatever {
method pull-one() { $!x }
}.new(x))
}
multi sub infix:<xx>(Mu \x, Int() $n) is pure {
multi sub infix:<xx>(Mu \x, Int $n) is pure {
if nqp::isgt_i((my int $elems = $n),0) {
my $list := nqp::setelems(nqp::list,$elems);
my int $i = -1;
Expand Down

0 comments on commit 5bacb05

Please sign in to comment.