summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-06-29 20:25:42 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-06-29 20:25:42 +0200
commitac63a9989289bd61542b9b50c25e57e0725383a7 (patch)
treef3148328836e0e9bdfd166ef9d36ba73f8074886
parent6f29041f0910e088e0e96f77e5aae8a39edbe5c5 (diff)
downloadNim-ac63a9989289bd61542b9b50c25e57e0725383a7.tar.gz
fixes #5974
-rw-r--r--compiler/jsgen.nim12
-rw-r--r--tests/js/trefbyvar.nim13
2 files changed, 20 insertions, 5 deletions
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 3e5cad9fd..a8a38ae4c 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -1248,17 +1248,21 @@ proc genSym(p: PProc, n: PNode, r: var TCompRes) =
   r.kind = resVal
 
 proc genDeref(p: PProc, n: PNode, r: var TCompRes) =
-  if mapType(p, n.sons[0].typ) == etyObject:
-    gen(p, n.sons[0], r)
+  let it = n.sons[0]
+  let t = mapType(p, it.typ)
+  if t == etyObject:
+    gen(p, it, r)
   else:
     var a: TCompRes
-    gen(p, n.sons[0], a)
+    gen(p, it, a)
     r.kind = resExpr
     if a.typ == etyBaseIndex:
       r.res = "$1[$2]" % [a.address, a.res]
-    elif n.sons[0].kind == nkCall:
+    elif it.kind == nkCall:
       let tmp = p.getTemp
       r.res = "($1 = $2, $1[0])[$1[1]]" % [tmp, a.res]
+    elif t == etyBaseIndex:
+      r.res = "$1[0]" % [a.res]
     else:
       internalError(n.info, "genDeref")
 
diff --git a/tests/js/trefbyvar.nim b/tests/js/trefbyvar.nim
index 68dd36543..73ddbed9e 100644
--- a/tests/js/trefbyvar.nim
+++ b/tests/js/trefbyvar.nim
@@ -2,7 +2,8 @@ discard """
   output: '''0
 5
 0
-5'''
+5
+@[1, 2]'''
 """
 
 # bug #2476
@@ -33,3 +34,13 @@ proc main =
   echo t.m
 
 main()
+
+# bug #5974
+type
+  View* = object
+    data: ref seq[int]
+
+let a = View(data: new(seq[int]))
+a.data[] = @[1, 2]
+
+echo a.data[]