summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-03-20 14:35:45 +0100
committerGitHub <noreply@github.com>2020-03-20 14:35:45 +0100
commit253e1b9e96111acb893411bd12540e46d158f9f6 (patch)
tree43065dfc19327ce02755d60bf1f89283f8218c23
parentf4dbdd311fbb3dd99dafca2179f17f2747531b4f (diff)
downloadNim-253e1b9e96111acb893411bd12540e46d158f9f6.tar.gz
fixes #13698 (#13706)
-rw-r--r--compiler/ccgexprs.nim4
-rw-r--r--tests/misc/tunsignedconv.nim7
2 files changed, 9 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 2d1005f5e..9c683a071 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1985,8 +1985,10 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc) =
     discard cgsym(p.module, raiser)
     # This seems to be bug-compatible with Nim version 1 but what we
     # should really do here is to check if uint64Value < high(int)
+    let n0t = n[0].typ
     let boundaryCast =
-      if n[0].typ.skipTypes(abstractVarRange).kind in {tyUInt, tyUInt32, tyUInt64}:
+      if n0t.skipTypes(abstractVarRange).kind in {tyUInt, tyUInt32, tyUInt64} or
+          (n0t.sym != nil and sfSystemModule in n0t.sym.owner.flags and n0t.sym.name.s == "csize"):
         "(NI64)"
       else:
         ""
diff --git a/tests/misc/tunsignedconv.nim b/tests/misc/tunsignedconv.nim
index 085d13aca..bc7aff30a 100644
--- a/tests/misc/tunsignedconv.nim
+++ b/tests/misc/tunsignedconv.nim
@@ -1,5 +1,6 @@
 discard """
-  output: '''uint'''
+  output: '''uint
+1'''
 """
 
 # Tests unsigned literals and implicit conversion between uints and ints
@@ -60,3 +61,7 @@ discard $x0
 
 const x1 = cast[uint](-1)
 discard $(x1,)
+
+# bug 13698
+let n: csize = 1
+echo n.int32