Skip to content

On binary operation common type inference #35

@dcodeIO

Description

@dcodeIO

Copying a note here from the compiler sources for discussion:

TODO: Currently, the common type of any binary expression is the first operand's type. This
differs from C and other languages where comparing an int to a long, in this order, upcasts
left to a long before comparison, instead of failing when trying to downcast right to an int.
NOTE that if we change the current behaviour, some examples, tests and wiki pages will have
to be updated, while compound binary operations must retain the previous behavior.

While I like the current behavior because it rather emits an error instead of doing possibly unwanted implicit type-conversions plus how easy it is to annotate the operation's type on the left operand (<i32>left < right guaranteeing i32.lt_s), it certainly is non-standard and there might be valid reasons to do it like C instead. Feel free to discuss.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions