Skip to content

Commit

Permalink
Make sure any Failures from .POSITIONS are passed on
Browse files Browse the repository at this point in the history
Fixes R#2788
  • Loading branch information
lizmat committed Apr 15, 2019
1 parent 7bbbebc commit 9ce87ee
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions src/core/array_slice.pm6
Expand Up @@ -343,13 +343,21 @@ multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, Bool() :$v!, *%other) is r
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block ) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
SELF[$block.POSITIONS(SELF)]
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
SELF[$pos]
)
)
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, Mu \assignee ) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
SELF[$block.POSITIONS(SELF)] = assignee
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
SELF[$pos] = assignee
)
)
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$BIND!) is raw {
Expand All @@ -359,59 +367,83 @@ multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$delete!,*%other)
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'delete', $delete, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'delete', $delete, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'delete', $delete, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'delete', $delete, %other )
)
)
)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$exists!,*%other) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'exists', $exists, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'exists', $exists, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'exists', $exists, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'exists', $exists, %other )
)
)
)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$kv!,*%other) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'kv', $kv, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'kv', $kv, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'kv', $kv, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'kv', $kv, %other )
)
)
)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$p!,*%other) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'p', $p, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'p', $p, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'p', $p, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'p', $p, %other )
)
)
)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$k!,*%other) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'k', $k, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'k', $k, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'k', $k, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'k', $k, %other )
)
)
)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$v!,*%other) is raw {
nqp::stmts(
(my $*INDEX = 'Effective index'),
nqp::if(
nqp::istype((my $pos := $block.POSITIONS(SELF)),Int),
SLICE_ONE_LIST( SELF, $pos, 'v', $v, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'v', $v, %other )
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure),
$pos,
nqp::if(
nqp::istype($pos,Int),
SLICE_ONE_LIST( SELF, $pos, 'v', $v, %other ),
SLICE_MORE_LIST( SELF, @$pos, 'v', $v, %other )
)
)
)
}
Expand Down

0 comments on commit 9ce87ee

Please sign in to comment.