mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
@@ -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)
|
||||
|
||||
15
tests/arc/tref_cast_error.nim
Normal file
15
tests/arc/tref_cast_error.nim
Normal 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])
|
||||
Reference in New Issue
Block a user