Skip to content

Two subtle bugs #170

@gwhitney

Description

@gwhitney

The browser test failure in mathjs PR 3568 uncovered two subtle bugs in typed-function:

  1. 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 from number -> string and Array -> 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 type number | 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.

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions