forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nim-lang#8404 JS backend doesn't handle float->int type conversion (
nim-lang#15950) [backport] * Fix nim-lang#8404 JS backend doesn't handle float->int type conversion * handle conv to uint as cast, discard other cases * limit to int32, times use int64 * toInt including tyInt64 break times timezones lib, ignore for now * also affect to vm * move to tests/misc/t8404.nim
- Loading branch information
Showing
2 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
discard """ | ||
targets: "c cpp js" | ||
""" | ||
template main() = | ||
block: # bug #8404 | ||
# can conv | ||
template float2int(T) = | ||
var a = -1.0 | ||
let b = T(a) | ||
doAssert b < 0 | ||
let c = b + 1 | ||
doAssert c is T | ||
doAssert c == 0 | ||
|
||
float2int(int8) | ||
float2int(int16) | ||
float2int(int32) | ||
float2int(int64) | ||
|
||
block: | ||
# can handle middle conv | ||
# `/` can trigger int to float | ||
template float2int(T) = | ||
let n = T(1 / 256) | ||
doAssert n == 0 | ||
|
||
float2int(int8) | ||
float2int(int16) | ||
float2int(int32) | ||
# float2int(int64) | ||
main() | ||
static: | ||
main() |