Skip to content
Permalink
Browse files

Multi-level EXISTS-POS should check for Failures

Fixes R#2929
  • Loading branch information...
lizmat committed May 28, 2019
1 parent f5f4190 commit ca7408e9fad113f64d7523a3b944116687ed4002
Showing with 27 additions and 4 deletions.
  1. +27 −4 src/core/Any.pm6
@@ -242,14 +242,37 @@ my class Any { # declared in BOOTSTRAP
die "Cannot use '{pos.^name}' as an index";
}
multi method EXISTS-POS(Any:D: \one, \two --> Bool:D) is raw {
self.AT-POS(one).EXISTS-POS(two)
nqp::if(
nqp::istype((my $one := self.AT-POS(one)),Failure),
False,
$one.EXISTS-POS(two)
)
}
multi method EXISTS-POS(Any:D: \one, \two,\three --> Bool:D) is raw {
self.AT-POS(one).AT-POS(two).EXISTS-POS(three)
nqp::if(
nqp::istype((my $one := self.AT-POS(one)),Failure)
|| nqp::istype((my $two := $one.AT-POS(one)),Failure),

This comment has been minimized.

Copy link
@HarmtH

HarmtH May 28, 2019

And this AT-POS(two)?

This comment has been minimized.

Copy link
@lizmat

lizmat May 28, 2019

Author Contributor

Good catch!

False,
$two.EXISTS-POS(two)

This comment has been minimized.

Copy link
@HarmtH

HarmtH May 28, 2019

Shouldn't this be EXISTS-POS(three)?

This comment has been minimized.

Copy link
@lizmat

lizmat May 28, 2019

Author Contributor

And another good Catch!

This comment has been minimized.

Copy link
@lizmat

lizmat May 28, 2019

Author Contributor

both fixed with c9a7892

)
}
multi method EXISTS-POS(Any:D: **@indices --> Bool:D) {
my $final := @indices.pop;
Rakudo::Internals.WALK-AT-POS(self,@indices).EXISTS-POS($final)
my $final := @indices.pop; # also reifies
my $target := self;
my $indices := nqp::getattr(@indices,List,'$!reified');
my int $elems = nqp::elems($indices);
my int $i = -1;
nqp::while(
nqp::islt_i(++$i,$elems),
nqp::if(
nqp::istype(
($target := $target.AT-POS(nqp::atpos($indices,$i))),
Failure
),
(return False)
)
);
$target.EXISTS-POS($final)
}

proto method AT-POS(|) is nodal {*}

1 comment on commit ca7408e

@lizmat

This comment has been minimized.

Copy link
Contributor Author

commented on ca7408e May 28, 2019

We clearly need more testing on this :-(

Please sign in to comment.
You can’t perform that action at this time.