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 /compiler | |
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 'compiler')
-rw-r--r-- | compiler/jsgen.nim | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 357e18000..34ebd306a 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2208,11 +2208,17 @@ proc genConv(p: PProc, n: PNode, r: var TCompRes) = if dest.kind == src.kind: # no-op conversion return - case dest.kind: - of tyBool: + let toInt = (dest.kind in tyInt..tyInt32) + let fromInt = (src.kind in tyInt..tyInt32) + let toUint = (dest.kind in tyUInt..tyUInt32) + let fromUint = (src.kind in tyUInt..tyUInt32) + if toUint and (fromInt or fromUint): + let trimmer = unsignedTrimmer(dest.size) + r.res = "($1 $2)" % [r.res, trimmer] + elif dest.kind == tyBool: r.res = "(!!($1))" % [r.res] r.kind = resExpr - of tyInt: + elif toInt: r.res = "(($1)|0)" % [r.res] else: # TODO: What types must we handle here? |