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

regression(0.18): nim js gives runtime error when appending to an uninitialized string #11783

Closed
timotheecour opened this issue Jul 19, 2019 · 0 comments · Fixed by #14158
Closed

Comments

@timotheecour
Copy link
Member

timotheecour commented Jul 19, 2019

nim js gives runtime error when appending an uninitialized string to an uninitialized string.
This works fine with nim c but gives runtime error with nim js:

reduced from a crash in a more complex program:

Example

proc fun(): string =
  # return "" # this removes the crash
  discard

var ret: string
# ret = ""  # this removes the crash
ret.add fun()

Current Output

/Users/timothee/git_clone/nim/timn/tests/nim/all/t0549.js:39
if (ret_311230[0] != null) { ret_311230[0] = (ret_311230[0]).concat(fun_311214()); } else { ret_311230[0] = fun_311214().slice(); };
                                                                                                                        ^

TypeError: Cannot read property 'slice' of null
    at Object.<anonymous> (/Users/timothee/git_clone/nim/timn/tests/nim/all/t0549.js:39:121)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11

Expected Output

should work (and print nothing), just like it does with nim c

Additional Information

  • Your Nim version (output of nim -v).
    latest devel f50e450

same bug with 0.19, 0.20

doesn't crash with 0.18, hence marking it as a regression, but not super sure 0.18 was 100% correct either, eg, i can make 0.18 crash by adding echo ret (but doesn't crash if i precede by ret.add "asdf")

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

Successfully merging a pull request may close this issue.

2 participants