Skip to content

Commit

Permalink
Fix advent test fail caused by grep optimization
Browse files Browse the repository at this point in the history
MMD candidates for grep and friends where selected on Callable and Regex,
instead of the more correct Callable:D and Regex:D.  This caused grep
expecting to smartmatch on Callable type to fail.
  • Loading branch information
lizmat committed May 18, 2014
1 parent 57a08ad commit 4a8eb3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
30 changes: 15 additions & 15 deletions src/core/Any.pm
Expand Up @@ -129,37 +129,37 @@ my class Any { # declared in BOOTSTRAP
}

proto method grep(|) { * }
multi method grep(Regex $test) is rw {
multi method grep(Regex:D $test) is rw {
self.map({ $_ if .match($test) });
}
multi method grep(&test) is rw {
self.map({ $_ if test($_) });
multi method grep(Callable:D $test) is rw {
self.map({ $_ if $test($_) });
}
multi method grep(Mu $test) is rw {
self.map({ $_ if $_ ~~ $test });
}

proto method grep-index(|) { * }
multi method grep-index(Regex $test) {
multi method grep-index(Regex:D $test) {
my $index = -1;
self.map: { $index++; +$index if .match($test) };
}
multi method grep-index(&test) {
multi method grep-index(Callable:D $test) {
my $index = -1;
self.map: { $index++; +$index if test($_) };
self.map: { $index++; +$index if $test($_) };
}
multi method grep-index(Mu $test) {
my $index = -1;
self.map: { $index++; +$index if $_ ~~ $test };
}

proto method first(|) { * }
multi method first(Regex $test) is rw {
multi method first(Regex:D $test) is rw {
self.map({ return $_ if .match($test) });
Nil;
}
multi method first(&test) is rw {
self.map({ return $_ if test($_) });
multi method first(Callable:D $test) is rw {
self.map({ return $_ if $test($_) });
Nil;
}
multi method first(Mu $test) is rw {
Expand All @@ -168,14 +168,14 @@ my class Any { # declared in BOOTSTRAP
}

proto method first-index(|) { * }
multi method first-index(Regex $test) {
multi method first-index(Regex:D $test) {
my $index = -1;
self.map: { $index++; return $index if .match($test) };
Nil;
}
multi method first-index(&test) {
multi method first-index(Callable:D $test) {
my $index = -1;
self.map: { $index++; return $index if test($_) };
self.map: { $index++; return $index if $test($_) };
Nil;
}
multi method first-index(Mu $test) {
Expand All @@ -185,14 +185,14 @@ my class Any { # declared in BOOTSTRAP
}

proto method last-index(|) { * }
multi method last-index(Regex $test) {
multi method last-index(Regex:D $test) {
my $index = self.elems;
self.reverse.map: { $index--; return $index if .match($test) };
Nil;
}
multi method last-index(&test) {
multi method last-index(Callable:D $test) {
my $index = self.elems;
self.reverse.map: { $index--; return $index if test($_) };
self.reverse.map: { $index--; return $index if $test($_) };
Nil;
}
multi method last-index(Mu $test) {
Expand Down
10 changes: 6 additions & 4 deletions src/core/SupplyOperations.pm
Expand Up @@ -119,10 +119,12 @@ my class SupplyOperations is repr('Uninstantiable') {
method tap(|c) {
my $source_tap;
my $tap = self.Supply::tap(|c, closing => {$source_tap.close});
$source_tap = $!source.tap( $!test ~~ Callable
?? $!test ~~ Regex
?? -> \val { self!more(val) if val.match($!test) }
!! -> \val { self!more(val) if $!test(val) }
$source_tap = $!source.tap( $!test.DEFINITE
?? $!test ~~ Callable
?? $!test ~~ Regex
?? -> \val { self!more(val) if val.match($!test) }
!! -> \val { self!more(val) if $!test(val) }
!! -> \val { self!more(val) if val ~~ $!test }
!! -> \val { self!more(val) if val ~~ $!test },
done => { self!done(); },
quit => -> $ex { self!quit($ex) }
Expand Down

0 comments on commit 4a8eb3d

Please sign in to comment.