error msg for #13864 (#13962)

Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
cooldome
2020-04-13 13:17:22 +01:00
committed by GitHub
parent 814f150184
commit 8ba915e449
2 changed files with 20 additions and 0 deletions

View File

@@ -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)

View File

@@ -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])