Skip to content
Permalink
Browse files

Further fix grep with regex returns

A fix was applied, but did not cover the case where we had adverbs.
Additionally, fix the case where we have a Junction of Regex being
returned from the `grep` block. This fixes the regressions reported
in #2643.
  • Loading branch information...
jnthn committed Jan 29, 2019
1 parent 6fe5377 commit c2e272ef682d54758ed1fac80d80e4ee4b1ee0fb
Showing with 17 additions and 6 deletions.
  1. +17 −6 src/core/Any-iterable-methods.pm6
@@ -942,7 +942,9 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
{
my \result := $test($_);
nqp::if(
nqp::istype(result, Regex) ?? result.ACCEPTS($_) !! result,
nqp::istype(result, Regex) || nqp::istype(result, Junction)
?? result.ACCEPTS($_)
!! result,
$_,
Empty)
},
@@ -1063,28 +1065,28 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
nqp::istype($t,Regex:D)
?? self!grep-k: { $t.ACCEPTS($_) }
!! nqp::istype($t,Callable:D)
?? self!grep-k: $t
?? self!grep-k: self!wrap-callable-for-grep($t)
!! self!grep-k: { $t.ACCEPTS($_) }
}
elsif nqp::atkey($storage,"kv") {
nqp::istype($t,Regex:D)
?? self!grep-kv: { $t.ACCEPTS($_) }
!! nqp::istype($t,Callable:D)
?? self!grep-kv: $t
?? self!grep-kv: self!wrap-callable-for-grep($t)
!! self!grep-kv: { $t.ACCEPTS($_) }
}
elsif nqp::atkey($storage,"p") {
nqp::istype($t,Regex:D)
?? self!grep-p: { $t.ACCEPTS($_) }
!! nqp::istype($t,Callable:D)
?? self!grep-p: $t
?? self!grep-p: self!wrap-callable-for-grep($t)
!! self!grep-p: { $t.ACCEPTS($_) }
}
elsif nqp::atkey($storage,"v") {
nqp::istype($t,Regex:D)
?? self!grep-accepts: $t
!! nqp::istype($t,Callable:D)
?? self!grep-callable: $t
?? self!grep-callable: self!wrap-callable-for-grep($t)
!! self!grep-accepts: $t
}
else {
@@ -1094,7 +1096,7 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
nqp::istype($t,Regex:D)
?? self!grep-accepts: $t
!! nqp::istype($t,Callable:D)
?? self!grep-callable: $t
?? self!grep-callable: self!wrap-callable-for-grep($t)
!! self!grep-accepts: $t
}
else {
@@ -1118,6 +1120,15 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
}
}

method !wrap-callable-for-grep($test) {
({
my \result := $test($_);
nqp::istype(result, Regex) || nqp::istype(result, Junction)
?? result.ACCEPTS($_)
!! result
})
}

proto method first(|) is nodal {*}
multi method first(Bool:D $t) {
Failure.new(X::Match::Bool.new( type => '.first' ))

0 comments on commit c2e272e

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