Skip to content

Commit

Permalink
Further fix grep with regex returns
Browse files Browse the repository at this point in the history
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 c2e272e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/core/Any-iterable-methods.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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' ))
Expand Down

0 comments on commit c2e272e

Please sign in to comment.