summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-08-15 19:28:13 +0800
committerGitHub <noreply@github.com>2024-08-15 19:28:13 +0800
commit298ada3412c9cf5971abc2b3b891b9bb8612e170 (patch)
treeb16e7f7357402b4c5913c8991d20e3e418732265
parent06b25bd2c40194f4b00d1d664492b6aed1dee91c (diff)
downloadNim-298ada3412c9cf5971abc2b3b891b9bb8612e170.tar.gz
fixes #23954; uint8 > 8 bit at compile-time (#23955)
fixes #23954
-rw-r--r--compiler/semfold.nim3
-rw-r--r--tests/int/t1.nim5
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index 69aaf2e90..450ae70fb 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -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)
diff --git a/tests/int/t1.nim b/tests/int/t1.nim
index f1d6c9a18..b8d6f9c92 100644
--- a/tests/int/t1.nim
+++ b/tests/int/t1.nim
@@ -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