Skip to content

Unit type compatibility is wrong in certain cases #877

@amyjko

Description

@amyjko

What happened?

Unit compatibility is inconsistent:
*1 + 1s Accepted, but incorrect.

  • 1s + 1 Correctly not accepted.
  • 1 · 1m Correctly accepted.

Anything else?

The root cause of this is is that + function on a number expects its right operand to be of the same type as the left operand. This is expressed as a UnitDeriver, which defines the expected type of the right operand as the left. That's why the second example above works.

But there is no corresponding constraint in the other direction, where the right must accept the left type. Moreover, unitless numbers are defined to accept numbers with units.

Overall, the implementation of the unit type checking is mostly right, but wrong in particular cases like this, and needs to be revised to account for the first case above.

What browsers are you seeing the problem on?

Chrome

What operating system are you using?

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    hardAn issue that requires lots of tricky design and implementation.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions