fixes #25222; cast[char](i) not trunc on JS (#25223)

fixes #25222

(cherry picked from commit 8f3bdb6951)
This commit is contained in:
lit
2025-10-17 00:21:37 +08:00
committed by narimiran
parent cf5b89f573
commit 60a204dfaa
2 changed files with 6 additions and 0 deletions

View File

@@ -2879,6 +2879,8 @@ proc genCast(p: PProc, n: PNode, r: var TCompRes) =
elif dest.kind in tyFloat..tyFloat64:
if src.kind in {tyInt64, tyUInt64} and optJsBigInt64 in p.config.globalOptions:
r.res = "Number($1)" % [r.res]
elif dest.kind == tyChar and (fromInt or fromUint):
r.res = "($1 & 255)" % [r.res]
elif (src.kind == tyPtr and mapType(p, src) == etyObject) and dest.kind == tyPointer:
r.address = r.res
r.res = "null"

View File

@@ -17,5 +17,9 @@ proc main() =
doAssert cast[int8](int16.high) == -1
block: # bug #25222
let ovf = 2 + int high char
doAssert cast[char](ovf) == '\1'
static: main()
main()