summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2020-04-13 13:17:22 +0100
committerGitHub <noreply@github.com>2020-04-13 14:17:22 +0200
commit8ba915e4498be3d17af894f5fb46c7b621ef5abb (patch)
tree2987dbec755ba838c79ed37f2113c1d4771ad00e
parent814f15018432f7657ed12277790bd444b09a2edc (diff)
downloadNim-8ba915e4498be3d17af894f5fb46c7b621ef5abb.tar.gz
error msg for #13864 (#13962)
Co-authored-by: cooldome <ariabushenko@bk.ru>
-rw-r--r--compiler/semexprs.nim5
-rw-r--r--tests/arc/tref_cast_error.nim15
2 files changed, 20 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 5c00ce1f8..3d41b592c 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -189,6 +189,11 @@ proc isCastable(conf: ConfigRef; dst, src: PType): bool =
     return false
   if skipTypes(src, abstractInst-{tyTypeDesc}).kind == tyTypeDesc:
     return false
+  if conf.selectedGC in {gcArc, gcOrc}:
+    let d = skipTypes(dst, abstractInst)
+    let s = skipTypes(src, abstractInst)
+    if d.kind == tyRef and s.kind == tyRef and s[0].isFinal != d[0].isFinal: 
+      return false
 
   var dstSize, srcSize: BiggestInt
   dstSize = computeSize(conf, dst)
diff --git a/tests/arc/tref_cast_error.nim b/tests/arc/tref_cast_error.nim
new file mode 100644
index 000000000..b0d2faf77
--- /dev/null
+++ b/tests/arc/tref_cast_error.nim
@@ -0,0 +1,15 @@
+discard """
+  cmd: "nim c --gc:arc $file"
+  errormsg: "expression cannot be cast to ref RootObj"
+  joinable: false
+"""
+
+type Variant* = object
+    refval: ref RootObj
+
+proc newVariant*[T](val: T): Variant =
+    let pt = T.new()
+    pt[] = val
+    result = Variant(refval: cast[ref RootObj](pt))
+
+var v = newVariant(@[1, 2, 3])