diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 806eca7442..0b9958ee4d 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2450,6 +2450,8 @@ proc genStmtList(p: BProc, n: PNode) = genStmtListExprImpl: genStmts(p, n[^1]) +from parampatterns import isLValue + proc upConv(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, n[0], a) @@ -2468,7 +2470,11 @@ proc upConv(p: BProc, n: PNode, d: var TLoc) = linefmt(p, cpsStmts, "if (!#isObj($1, $2)){ #raiseObjectConversionError(); $3}$n", [r, checkFor, raiseInstr(p)]) if n[0].typ.kind != tyObject: - putIntoDest(p, d, n, + if n.isLValue: + putIntoDest(p, d, n, + "(*(($1*) (&($2))))" % [getTypeDesc(p.module, n.typ), rdLoc(a)], a.storage) + else: + putIntoDest(p, d, n, "(($1) ($2))" % [getTypeDesc(p.module, n.typ), rdLoc(a)], a.storage) else: putIntoDest(p, d, n, "(*($1*) ($2))" % diff --git a/tests/ccgbugs/t14160.nim b/tests/ccgbugs/t14160.nim new file mode 100644 index 0000000000..be7088e291 --- /dev/null +++ b/tests/ccgbugs/t14160.nim @@ -0,0 +1,15 @@ +type + TPassContext = object of RootObj + PPassContext = ref TPassContext + + PCtx = ref object of TPassContext + a: int + + ModuleGraph = object + vm: RootRef + +proc main() = + var g = ModuleGraph(vm: new(Pctx)) + PCtx(g.vm) = nil #This generates invalid C code + +main()