Skip to content

Type coersion inside tuple #7003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
soanvig opened this issue Sep 2, 2024 · 0 comments · Fixed by #7024
Closed

Type coersion inside tuple #7003

soanvig opened this issue Sep 2, 2024 · 0 comments · Fixed by #7024

Comments

@soanvig
Copy link

soanvig commented Sep 2, 2024

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants