summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/jsgen.nim2
-rw-r--r--tests/js/trefbyvar.nim15
2 files changed, 17 insertions, 0 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index a8a38ae4c..ae5294a81 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -939,6 +939,8 @@ proc genAsgnAux(p: PProc, x, y: PNode, noCopyNeeded: bool) =
       if y.kind == nkCall:
         let tmp = p.getTemp(false)
         lineF(p, "var $1 = $4; $2 = $1[0]; $3 = $1[1];$n", [tmp, a.address, a.res, b.rdLoc])
+      elif b.typ == etyBaseIndex:
+        lineF(p, "$# = $#;$n", [a.res, b.rdLoc])
       else:
         internalError(x.info, "genAsgn")
     else:
diff --git a/tests/js/trefbyvar.nim b/tests/js/trefbyvar.nim
index 314a02543..d440fcc64 100644
--- a/tests/js/trefbyvar.nim
+++ b/tests/js/trefbyvar.nim
@@ -52,3 +52,18 @@ input.add(nil)
 input.add(new string)
 input[1][] = "~"
 echo input[1][]
+
+# bug #5517
+type
+  TypeA1 = object of RootObj
+    a_impl: int
+    b_impl: string
+    c_impl: pointer
+
+proc initTypeA1(a: int; b: string; c: pointer = nil): TypeA1 =
+  result.a_impl = a
+  result.b_impl = b
+  result.c_impl = c
+
+let x = initTypeA1(1, "a")
+doAssert($x == "(a_impl: 1, b_impl: a, c_impl: ...)")