diff options
author | Bung <crc32@qq.com> | 2020-11-13 20:44:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 13:44:48 +0100 |
commit | 797cb2e67b084f28474cc5d4251e57275c1e8f5f (patch) | |
tree | 4556d83427078d73df1b7037d44127d3f6726b27 /tests | |
parent | d802a4a669aa8661b4ba80abbd9310b93b9fe605 (diff) | |
download | Nim-797cb2e67b084f28474cc5d4251e57275c1e8f5f.tar.gz |
Fix #8404 JS backend doesn't handle float->int type conversion (#15950) [backport]
* Fix #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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/t8404.nim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/misc/t8404.nim b/tests/misc/t8404.nim new file mode 100644 index 000000000..87991071c --- /dev/null +++ b/tests/misc/t8404.nim @@ -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() |