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

JS: no bound checks at top level #14153

Closed
metagn opened this issue Apr 28, 2020 · 0 comments · Fixed by #14158
Closed

JS: no bound checks at top level #14153

metagn opened this issue Apr 28, 2020 · 0 comments · Fixed by #14158

Comments

@metagn
Copy link
Collaborator

metagn commented Apr 28, 2020

This only happens on top level, it works inside proc main or similar. --boundchecks:on doesn't help.

Example

var x = @[1, 2, 3]

echo x[5]
x[5] = 8

Current Output

undefined

Expected Output

Error: unhandled exception: index 5 not in 0 .. 2 [IndexError]

Possible Solution

  • jsgen.genArrayAccess checks for optBoundsCheck in p.options which evaluates to false at top level and true anywhere else.
  • Workaround:
var x = @[1, 2, 3]

proc main =
  echo x[5]
  x[5] = 8
main()
$ nim -v
Nim Compiler Version 1.3.1 [Windows: amd64]

git hash: 3b5a504692495324afdb7c20159122e66100f767
@metagn metagn changed the title JS: no index range checks for seq/string JS: no index range checks Apr 28, 2020
@metagn metagn changed the title JS: no index range checks JS: no index range checks at top level Apr 29, 2020
@metagn metagn changed the title JS: no index range checks at top level JS: no bound checks at top level Apr 29, 2020
Araq pushed a commit that referenced this issue Apr 29, 2020
* many bugfixes for js

fixes #12672, fixes #14153, closes #14123, closes #11331, fixes #11783, fixes #13966, fixes #14087, fixes #14117, closes #12256.

mostly fixes the fact that it was allowed to assign to newly created temp variables. additionally attempts to get rid of null initialized seqs/strings (though they might pop up here and there); this simplifies a lot of things and makes code size smaller. even if null seqs/strings pop up here and there it's still better than all those bugs existing.

* formatting fixes

* CI fixes

* more CI fixes
EchoPouet pushed a commit to EchoPouet/Nim that referenced this issue Jun 13, 2020
* many bugfixes for js

fixes nim-lang#12672, fixes nim-lang#14153, closes nim-lang#14123, closes nim-lang#11331, fixes nim-lang#11783, fixes nim-lang#13966, fixes nim-lang#14087, fixes nim-lang#14117, closes nim-lang#12256.

mostly fixes the fact that it was allowed to assign to newly created temp variables. additionally attempts to get rid of null initialized seqs/strings (though they might pop up here and there); this simplifies a lot of things and makes code size smaller. even if null seqs/strings pop up here and there it's still better than all those bugs existing.

* formatting fixes

* CI fixes

* more CI fixes
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 a pull request may close this issue.

1 participant