Skip to content

Commit 8f3bdb6

Browse files
authored
fixes #25222; cast[char](i) not trunc on JS (#25223)
fixes #25222
1 parent 31d64b5 commit 8f3bdb6

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

compiler/jsgen.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,8 @@ proc genCast(p: PProc, n: PNode, r: var TCompRes) =
28792879
elif dest.kind in tyFloat..tyFloat64:
28802880
if src.kind in {tyInt64, tyUInt64} and optJsBigInt64 in p.config.globalOptions:
28812881
r.res = "Number($1)" % [r.res]
2882+
elif dest.kind == tyChar and (fromInt or fromUint):
2883+
r.res = "($1 & 255)" % [r.res]
28822884
elif (src.kind == tyPtr and mapType(p, src) == etyObject) and dest.kind == tyPointer:
28832885
r.address = r.res
28842886
r.res = "null"

tests/cast/tcast.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ proc main() =
1717

1818
doAssert cast[int8](int16.high) == -1
1919

20+
block: # bug #25222
21+
let ovf = 2 + int high char
22+
doAssert cast[char](ovf) == '\1'
23+
2024
static: main()
2125
main()

0 commit comments

Comments
 (0)