[CLJ-735] Improve error message when a protocol method is not found Created: 04/Feb/11 Updated: 09/Dec/11
|Affects Version/s:||Release 1.2|
|Fix Version/s:||Approved Backlog|
If you call a protocol function but pass the wrong arity (forget an argument for example), you currently a message that says "No single method ... of interface ... found for function ... of protocol ...". The code in question is getting matching methods from the Reflector and creates this message if the number of matches != 1.
There are really two cases there:
I propose that the == 0 case instead should have slightly different text at the beginning and a hint as to the intended arity within it:
"No method: ... of interface ... with arity ... found for function ... of protocol ...".
The >1 case should have similar changes: "Multiple methods: ... of interface ... with arity ... found for function ... of protocol ...".
Patch is attached. I used case which presumably should have better performance than a nested if/else. I was not sure whether the reported arity should match the actual Java method arity or Clojure protocol function arity (including the target). I did the former.
I did not add a test as I wasn't sure whether checking error messages in tests was appropriate or not. Happy to add that if requested.
|Comment by Chas Emerick [ 14/Jul/11 6:39 AM ]|
I think it should be the latter. The message is emitted when the protocol methods are being invoked through the corresponding function, so it should be consistent with the errors emitted by regular functions.
+1 for some tests, too. There certainly are tests for reflection warnings and such.
FWIW, I'm happy to take this on if Alex is otherwise occupied.