Skip to content
Permalink
Browse files

Add specific info for Foo ~~ (10 => Bar)

In response to R#2512

    $ perl6 -e 'Any ~~ (10 => "ten")'
    No such method '10' for invocant of type 'Any'
    Did you try to smartmatch against a Pair specifically?  If so,
    then the key of the Pair should be a valid method name, not '10'
  • Loading branch information...
lizmat committed Dec 31, 2018
1 parent 04dd52f commit b6c8f5ed19669dd4ed0522370125446ef300fde8
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/core/Pair.pm6
@@ -56,7 +56,17 @@ my class Pair does Associative {
$!value.ACCEPTS(nqp::getattr(nqp::decont($p),Pair,'$!value'));
}
multi method ACCEPTS(Pair:D: Mu $other) {
$other."$!key"().Bool === $!value.Bool
nqp::if(
nqp::can($other,(my $method := $!key.Str)),
($other."$method"().Bool === $!value.Bool),
X::Method::NotFound.new(
invocant => $other,
method => $method,
typename => $other.^name,
addendum => "Did you try to smartmatch against a Pair specifically? If so, then the
key of the Pair should be a valid method name, not '$method'."
).throw
)
}

method Pair() { self }

0 comments on commit b6c8f5e

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