mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 13:07:48 +00:00
Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
@@ -2189,6 +2189,11 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
|
||||
elif etyp.kind == tyBool and srcTyp.kind in IntegralTypes:
|
||||
putIntoDest(p, d, e, "(($1) != 0)" % [rdCharLoc(a)], a.storage)
|
||||
else:
|
||||
if etyp.kind == tyPtr:
|
||||
# generates the definition of structs for casts like cast[ptr object](addr x)[]
|
||||
let internalType = etyp.skipTypes({tyPtr})
|
||||
if internalType.kind == tyObject:
|
||||
discard getTypeDesc(p.module, internalType)
|
||||
putIntoDest(p, d, e, "(($1) ($2))" %
|
||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
||||
|
||||
|
||||
27
tests/ccgbugs/t20141.nim
Normal file
27
tests/ccgbugs/t20141.nim
Normal file
@@ -0,0 +1,27 @@
|
||||
discard """
|
||||
joinable: false
|
||||
"""
|
||||
|
||||
# bug #20141
|
||||
type
|
||||
A = object
|
||||
B = object
|
||||
U = proc()
|
||||
|
||||
proc m(h: var B) = discard
|
||||
|
||||
template n[T, U](x: U): T =
|
||||
static: doAssert true
|
||||
cast[ptr T](addr x)[]
|
||||
|
||||
proc k() =
|
||||
var res: A
|
||||
m(n[B](res))
|
||||
|
||||
proc w(mounter: U) = discard
|
||||
|
||||
proc mount(proto: U) = discard
|
||||
proc v() = mount k
|
||||
|
||||
# This is required for failure
|
||||
w(v)
|
||||
Reference in New Issue
Block a user