-
Notifications
You must be signed in to change notification settings - Fork 22
Description
The browser test failure in mathjs PR 3568 uncovered two subtle bugs in typed-function:
-
The typed-function documentation describes that in a choice between two different conversions, the earlier conversion in the list of conversions is preferred. However, that preference was not always being followed. In fact, there was already a test here in typed-function that displayed the bug, just the expected answer validated the non-conformant behavior. Namely, in conversions.test.js, there is a function given two signatures
(string, Array)and(number, boolean)along with conversions fromnumber -> stringandArray -> boolean, critically in that order. Thus, there are two ways typed-function might handle a(number, Array)input: either convert the number to a string and use the(string, Array)implementation, or convert the Array to a boolean and use the(number, boolean)implementation. According to the selection principle, typed-function should chose the former, but it was choosing the latter (and the unit test was blessing that). I will also adde a simpler example in
the same file. It will be called fn3, and it has a single signature with typenumber | Object | string. The typed-function package is choosing the wrong one of these to convert a boolean to in the presence of conversions to all three types. -
The compareSignature function was not transitive, so the result of sorting signatures by this comparison was not well-defined (that's the more primary direct cause of the browser test failure). I am not really sure how to test this here in typed-function, so the primary thing I will be relying on is that using the modified typed-function eliminates the browser-test vs node-test discrepancy.
PR to come momentarily.