Skip to content
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

fix(compiler): Provide appropriate error during invalid array access #1556

Merged
merged 1 commit into from
Dec 23, 2022

Conversation

ospencer
Copy link
Member

This PR fixes an issue where a potential non-integer or heap-allocated index for an array get/set may not result in an error. It also provides a better error for non-integer indexes.

@ospencer ospencer self-assigned this Dec 18, 2022
Copy link
Member

@phated phated left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions

compiler/src/codegen/compcore.re Show resolved Hide resolved
compiler/src/codegen/compcore.re Show resolved Hide resolved
),
Expression.Block.make(
wasm_mod,
gensym_label("IndexNotSimpleInteger"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a symptom that XX.toNumber should reduce its argument to the smallest containing integer, rather than be a no-op...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think how it works now is correct (since the flexibility is the point of Number), but we should definitely have a utility that does let you round/truncate. It gets kinda hairy for floats, since we support bigints. My basic math tells me that the worst case conversion of a float64 to a bigint would be a bigint with 16 limbs, so maybe not actually so bad.

That said though, I could see us converting whole numbers to ints. 3.0 becoming 3, that sort of thing.

But yeah, food for thought.

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; I left one piece of food for thought, but that's beyond the scope of this PR.

@ospencer ospencer merged commit 3d7b9e3 into main Dec 23, 2022
@ospencer ospencer deleted the oscar/array-access-err branch December 23, 2022 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants