summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-03-31 02:27:02 -0700
committerGitHub <noreply@github.com>2021-03-31 11:27:02 +0200
commitb18307f94060d2f672a83d72c557f3856368b73a (patch)
tree6adf79c49ce828c125637031ff9e720c13c11d4c
parent6d7d1e60fea201109bdafce550622b5b49e23323 (diff)
downloadNim-b18307f94060d2f672a83d72c557f3856368b73a.tar.gz
fix #17572 (#17586)
-rw-r--r--compiler/vm.nim3
-rw-r--r--tests/misc/tunsignedconv.nim16
2 files changed, 18 insertions, 1 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index baaf0f14e..e3ba2994f 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -415,7 +415,8 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType):
     else:
       internalError(c.config, "cannot convert to string " & desttyp.typeToString)
   else:
-    case skipTypes(desttyp, abstractVarRange).kind
+    let desttyp = skipTypes(desttyp, abstractVarRange)
+    case desttyp.kind
     of tyInt..tyInt64:
       dest.ensureKind(rkInt)
       case skipTypes(srctyp, abstractRange).kind
diff --git a/tests/misc/tunsignedconv.nim b/tests/misc/tunsignedconv.nim
index b9463b5f0..0acb39106 100644
--- a/tests/misc/tunsignedconv.nim
+++ b/tests/misc/tunsignedconv.nim
@@ -79,3 +79,19 @@ except RangeDefect:
   success = true
 
 doAssert success, "conversion should fail at runtime"
+
+template main() =
+  # xxx move all tests under here so it gets tested in CT and RT
+  block: # bug #17572
+    type T = distinct uint64
+    func f(x: uint64): auto =
+      let a = T(x)
+      (x, a.uint64)
+    const x = 1'u64 shl 63 or 7
+    const b = T(x)
+    doAssert b.uint64 == 9223372036854775815'u64
+    doAssert $b.uint64 == "9223372036854775815"
+    doAssert f(x) == (9223372036854775815'u64, 9223372036854775815'u64)
+
+static: main()
+main()