Skip to content

Type coersion inside tuple #7003

Closed
Closed

Description

@soanvig

Rescript version: 11.1.3

Working code:

// Note: none of the values are casted to float
let (x, y) = (ev->DOM.MouseEvent.offsetX, ev->DOM.MouseEvent.offsetY)
// Note: both values are casted to float
let (x, y) = (ev->DOM.MouseEvent.offsetX, ev->DOM.MouseEvent.offsetY) :> (float, float)
// Note: only first value is casted to float
let (x, y) = (ev->DOM.MouseEvent.offsetX :> float, ev->DOM.MouseEvent.offsetY)
// Note: only second value is casted to float. *there are parens around the second item
let (x, y) = (ev->DOM.MouseEvent.offsetX, (ev->DOM.MouseEvent.offsetY :> float))

Not working code:

// Note: coersion in both values
// ERROR: Did you forget a `,` here?
let (x, y) = (ev->DOM.MouseEvent.offsetX :> float, ev->DOM.MouseEvent.offsetY :> float)
// Note: coersion only in second value
// ERROR: Did you forget a `,` here?
let (x, y) = (ev->DOM.MouseEvent.offsetX, ev->DOM.MouseEvent.offsetY :> float)

This looks like a bug (or syntax incosistency at least), because type coersion for first item works without parens, but doesn't work for the second (requires parens). It looks like a parser bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions