Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #12978 #13012

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,14 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: var TLoc,
linefmt(p, section, "$1.m_type = $2;$n", [r, genTypeInfo(p.module, t, a.lode.info)])
of frEmbedded:
if optTinyRtti in p.config.globalOptions:
var tmp: TLoc
if mode == constructRefObj:
var n = newNodeIT(nkObjConstr, a.lode.info, t)
n.add newNodeIT(nkType, a.lode.info, t)
genObjConstr(p, n, a)
let objType = t.skipTypes(abstractInst+{tyRef})
rawConstExpr(p, newNodeIT(nkType, a.lode.info, objType), tmp)
linefmt(p, cpsStmts,
"#nimCopyMem((void*)$1, (NIM_CONST void*)&$2, sizeof($3));$n",
[rdLoc(a), rdLoc(tmp), getTypeDesc(p.module, objType)])
else:
var tmp: TLoc
rawConstExpr(p, newNodeIT(nkType, a.lode.info, t), tmp)
genAssignment(p, a, tmp, {})
else:
Expand Down
25 changes: 24 additions & 1 deletion tests/destructor/tcomplexobjconstr.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
discard """
output: "true"
output: '''true
OK'''
cmd: "nim c --gc:arc $file"
"""

Expand Down Expand Up @@ -31,3 +32,25 @@ assert y.more[2] of MyObject1
assert y.more[2] of RootObj

echo "true"

# bug #12978
type
Vector2* = object of RootObj
x*, y*: float

type
Vertex* = ref object
point*: Vector2

proc newVertex*(p: Vector2): Vertex =
return Vertex(point: p)

proc createVertex*(p: Vector2): Vertex =
result = newVertex(p)

proc p =
var x = Vector2(x: 1, y: 2)
let other = createVertex(x)
echo "OK"

p()