Skip to content
Permalink
Browse files

Make `.grep: { /regex/ }` work again

This worked for the slightly dubious reason that `grep` happened to set
`$_`, and boolify the regex that was returned. This was relying on an
implementation detail - there's nothing that says `grep` has to have the
test element in its `$_` - however there's code in the wild that relies
on this construct, and it's hard to argue that it shouldn't DWIM.

It stopped working when the `$_` in `grep` ceased to be dynamically
available, as it no longer needs to be. For now, solve it by making
`grep` explictly handle the case where a Regex is returned to it. This
fixes #2614. If in the future we accept the proposal that a regex will,
when cloned, capture the `$_` in the scope it literally appears in for
the purpose of use in boolean or sink context, as proposed in #2608,
then this change can be removed again. It's also a good sign for that
proposal that it happens to solve this problem neatly.
  • Loading branch information...
jnthn committed Jan 17, 2019
1 parent 5d70797 commit f71ca0de120acea4f739320dbe7ddef3c08b6dd2
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/core/Any-iterable-methods.pm6
@@ -939,7 +939,13 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
$test.count == 1,
sequential-map(
self.iterator,
{ nqp::if($test($_),$_,Empty) },
{
my \result := $test($_);
nqp::if(
nqp::istype(result, Regex) ?? result.ACCEPTS($_) !! result,
$_,
Empty)
},
Any)
,
nqp::stmts(

0 comments on commit f71ca0d

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