diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 34ebd306a7..3a1ef7fbb8 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1074,8 +1074,13 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) = lineF(p, "$1 = $2;$n", [a.rdLoc, b.rdLoc]) else: useMagic(p, "nimCopy") - lineF(p, "nimCopy($1, $2, $3);$n", - [a.res, b.res, genTypeInfo(p, y.typ)]) + # supports proc getF(): var T + if x.kind in {nkHiddenDeref, nkDerefExpr} and x[0].kind in nkCallKinds: + lineF(p, "nimCopy($1, $2, $3);$n", + [a.res, b.res, genTypeInfo(p, y.typ)]) + else: + lineF(p, "$1 = nimCopy($1, $2, $3);$n", + [a.res, b.res, genTypeInfo(p, y.typ)]) of etyBaseIndex: if a.typ != etyBaseIndex or b.typ != etyBaseIndex: if y.kind == nkCall: diff --git a/tests/js/t12303.nim b/tests/js/t12303.nim new file mode 100644 index 0000000000..270d82cedb --- /dev/null +++ b/tests/js/t12303.nim @@ -0,0 +1,16 @@ +discard """ + output: "{ b: 2 }" +""" + +import jsconsole, jsffi + +type + A = ref object + b: B + + B = object + b: int + +var a = cast[A](js{}) +a.b = B(b: 2) +console.log a.b diff --git a/tests/varres/tvarres0.nim b/tests/varres/tvarres0.nim index 0f89c7e719..94bdb4a06f 100644 --- a/tests/varres/tvarres0.nim +++ b/tests/varres/tvarres0.nim @@ -4,6 +4,7 @@ discard """ 123 1234 12345 +123456 ''' """ @@ -28,6 +29,8 @@ getF().a = 1234 echo getF().a getF() = Foo(a: 12345) echo getF().a +(addr getF())[] = Foo(a: 123456) +echo getF().a block: # #13848