Skip to content

Commit

Permalink
Slightly improve error message
Browse files Browse the repository at this point in the history
cross( (1,2,3), (4,5,6), :with(42) ) would die with the perplexing
error message: "Unexpected named argument 'with' passed".  This is
caused by the candidate that *does* accept :with has a Callable
constraint on it.  And since 42 is not a Callable, that candidate
is not selected, so the next candidate is, except for the fact that
that candidate does not accept a :with named parameter.

By removing the Callable constraint on the :with! candidate, the
error becomes: Type check failed in binding to parameter '&op';
expected Callable but got Int (42).  Still not pretty, but a lot
less perplexing.  Only other alternative would be to create an
additional candidate just to be able to create a more awesome
error message.  It's been done before, but this doesn't feel like
it is too much of a beginners trap.  Although a beginner found it:

  https://stackoverflow.com/questions/62202221/how-do-i-take-a-reference-to-new/62202837#62202837
  • Loading branch information
lizmat committed Jun 4, 2020
1 parent 9fe471c commit 496e916
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core.c/List.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -1706,8 +1706,8 @@ multi sub infix:<cmp>(@a, @b --> Order:D) {
}

proto sub infix:<X>(|) is pure {*}
multi sub infix:<X>(+lol, :&with! --> Seq:D) {
Seq.new(Rakudo::Iterator.CrossIterablesOp(lol,&with))
multi sub infix:<X>(+lol, :$with! --> Seq:D) {
Seq.new(Rakudo::Iterator.CrossIterablesOp(lol,$with))
}
multi sub infix:<X>(+lol --> Seq:D) {
Seq.new(Rakudo::Iterator.CrossIterablesOp(lol,&infix:<,>))
Expand Down

0 comments on commit 496e916

Please sign in to comment.