Skip to content

Commit 0ecb709

Browse files
authored
1 parent c949b81 commit 0ecb709

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

compiler/cgen.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,14 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: var TLoc,
362362
linefmt(p, section, "$1.m_type = $2;$n", [r, genTypeInfo(p.module, t, a.lode.info)])
363363
of frEmbedded:
364364
if optTinyRtti in p.config.globalOptions:
365+
var tmp: TLoc
365366
if mode == constructRefObj:
366-
var n = newNodeIT(nkObjConstr, a.lode.info, t)
367-
n.add newNodeIT(nkType, a.lode.info, t)
368-
genObjConstr(p, n, a)
367+
let objType = t.skipTypes(abstractInst+{tyRef})
368+
rawConstExpr(p, newNodeIT(nkType, a.lode.info, objType), tmp)
369+
linefmt(p, cpsStmts,
370+
"#nimCopyMem((void*)$1, (NIM_CONST void*)&$2, sizeof($3));$n",
371+
[rdLoc(a), rdLoc(tmp), getTypeDesc(p.module, objType)])
369372
else:
370-
var tmp: TLoc
371373
rawConstExpr(p, newNodeIT(nkType, a.lode.info, t), tmp)
372374
genAssignment(p, a, tmp, {})
373375
else:

tests/destructor/tcomplexobjconstr.nim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
discard """
2-
output: "true"
2+
output: '''true
3+
OK'''
34
cmd: "nim c --gc:arc $file"
45
"""
56

@@ -31,3 +32,25 @@ assert y.more[2] of MyObject1
3132
assert y.more[2] of RootObj
3233

3334
echo "true"
35+
36+
# bug #12978
37+
type
38+
Vector2* = object of RootObj
39+
x*, y*: float
40+
41+
type
42+
Vertex* = ref object
43+
point*: Vector2
44+
45+
proc newVertex*(p: Vector2): Vertex =
46+
return Vertex(point: p)
47+
48+
proc createVertex*(p: Vector2): Vertex =
49+
result = newVertex(p)
50+
51+
proc p =
52+
var x = Vector2(x: 1, y: 2)
53+
let other = createVertex(x)
54+
echo "OK"
55+
56+
p()

0 commit comments

Comments
 (0)