Skip to content

Commit

Permalink
fixes #23954; uint8 > 8 bit at compile-time (#23955)
Browse files Browse the repository at this point in the history
fixes #23954
  • Loading branch information
ringabout authored Aug 15, 2024
1 parent 06b25bd commit 298ada3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P
of tyChar, tyUInt..tyUInt64, tyInt..tyInt64:
var val = a.getOrdValue
if dstTyp.kind in {tyUInt..tyUInt64}:
result = newIntNodeT(val, n, idgen, g)
result = newIntNodeT(maskBytes(val, getSize(g.config, dstTyp)), n, idgen, g)
result.transitionIntKind(nkUIntLit)
result.typ = dstTyp
else:
if check: rangeCheck(n, val, g)
result = newIntNodeT(val, n, idgen, g)
Expand Down
5 changes: 5 additions & 0 deletions tests/int/t1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ block:
# bug #14522
doAssert 0xFF000000_00000000.uint64 == 18374686479671623680'u64

block: # bug #23954
let testRT_u8 : uint8 = 0x107.uint8
doAssert testRT_u8 == 7
const testCT_u8 : uint8 = 0x107.uint8
doAssert testCT_u8 == 7

0 comments on commit 298ada3

Please sign in to comment.