Skip to content

Commit

Permalink
Add checks for HOW WHAT WHO manually
Browse files Browse the repository at this point in the history
As suggested as a solution for #3854
  • Loading branch information
lizmat committed Aug 20, 2020
1 parent bb7c617 commit b054f9f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/core.c/Exception.pm6
Expand Up @@ -201,6 +201,23 @@ my class X::Method::NotFound is Exception {
}

my $public_suggested = 0;
sub find_public_suggestion($before, $after --> Nil) {
if $before.fc eq $after.fc {
$public_suggested = 1;
%suggestions{$after} = ""; # assume identity
}
else {
my $dist := StrDistance.new(
before => $before.fc,
after => $after.fc
);
if $dist <= $max_length {
$public_suggested = 1;
%suggestions{$after} = ~$dist;
}
}
}

if nqp::can($!invocant.HOW, 'methods') {
# $!invocant can be a KnowHOW which method `methods` returns a hash, not a list.
my $invocant_methods :=
Expand All @@ -213,19 +230,12 @@ my class X::Method::NotFound is Exception {
if $method_candidate.^name eq 'Submethod' # a submethod
&& !$invocant_methods{$method_name}; # unknown method

if $.method.fc eq $method_name.fc {
%suggestions{$method_name} = ""; # assume identity
}
else {
my $dist = StrDistance.new(
before => $.method.fc,
after => $method_name.fc
);
if $dist <= $max_length {
$public_suggested = 1;
%suggestions{$method_name} = ~$dist;
}
}
find_public_suggestion($.method, $method_name);
}

# handle special unintrospectable cases
for <HOW WHAT WHO> -> $method_name {
find_public_suggestion($.method, $method_name);
}
}

Expand Down

0 comments on commit b054f9f

Please sign in to comment.