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

uint inplace add in if branch is omitted when compiled to JS #10697

Closed
liwt31 opened this issue Feb 17, 2019 · 1 comment

Comments

Projects
None yet
5 participants
@liwt31
Copy link

commented Feb 17, 2019

If an if branch contains one and only one inplace-add statement of an unsigned integer, the content of the branch is omitted when compiled to JS.

Example

proc test =
  var val = uint16(0)
  var i = 0
  if i < 2:
    val += uint16(1)
  echo int(val)

test()

Current Output

For c target, the output is correct, which is 1. For JS target, the output is 0. The compiled JS reads:

function test_25003() {
	var F={procname:"test.test",prev:framePtr,filename:"test.nim",line:0};
	framePtr = F;
		F.line = 2;
		var val_25005 = 0;
		F.line = 3;
		var i_25007 = 0;
		if ((i_25007 < 2)) {
		F.line = 5;
		}
		
		F.line = 6;
		rawEcho(cstrToNimstr((((val_25005)|0))+""));
	framePtr = F.prev;
}

Additional Information

Nim Compiler Version 0.19.4 [Linux: amd64]
Compiled at 2019-02-01
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: b6d96cafc8bcad1f3d32f2910b25cd11a93f7751
active boot switches: -d:release

A workaround is to use things like x = x + 1

@krux02 krux02 added JS Codegen labels Feb 17, 2019

@Araq Araq added the Showstopper label Feb 17, 2019

@alaviss

This comment has been minimized.

Copy link
Contributor

commented Feb 19, 2019

With 257965e merged I believe this issue should be closed.

@narimiran narimiran closed this Feb 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.