summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorNeelesh Chandola <neelesh.chandola@outlook.com>2019-12-05 22:01:51 +0530
committerAndreas Rumpf <rumpf_a@web.de>2019-12-05 17:31:51 +0100
commit1db21721ec816e01ef91633941e0295f7724e1f7 (patch)
treece90b3d9e4737e8eee2d886ca946f688bfe4e667
parent3fbb3bfd3f440c059d6290c12834a38a61da98f2 (diff)
downloadNim-1db21721ec816e01ef91633941e0295f7724e1f7.tar.gz
Fixed objects being erroneously zeroed out before object construction (#12814) [backport]
-rw-r--r--compiler/aliases.nim3
-rw-r--r--tests/objects/t12753.nim22
2 files changed, 25 insertions, 0 deletions
diff --git a/compiler/aliases.nim b/compiler/aliases.nim
index 34b81cbad..0006c9fe6 100644
--- a/compiler/aliases.nim
+++ b/compiler/aliases.nim
@@ -193,4 +193,7 @@ proc isPartOf*(a, b: PNode): TAnalysisResult =
         if res != arNo:
           result = res
           if res == arYes: break
+    of nkBracket:
+      if b.len > 0:
+        result = isPartOf(a, b[0])
     else: discard
diff --git a/tests/objects/t12753.nim b/tests/objects/t12753.nim
new file mode 100644
index 000000000..1009433be
--- /dev/null
+++ b/tests/objects/t12753.nim
@@ -0,0 +1,22 @@
+discard """
+  output: '''
+(v: [(v: [0.0, 1.1]), (v: [2.2, 3.3])])
+(v: [(v: [0.0, 1.1]), (v: [2.2, 3.3])])
+'''
+"""
+
+type
+  V = object
+    v:array[2,float]
+  M = object
+    v:array[2,V]
+
+var
+  a = M(v:[ V(v:[0.0,1.0]), V(v:[2.0,3.0]) ])
+  b = M(v:[ V(v:[0.0,0.1]), V(v:[0.2,0.3]) ])
+
+echo M(v: [V(v: [b.v[0].v[0] + a.v[0].v[0], b.v[0].v[1] + a.v[0].v[1]]),
+       V(v: [b.v[1].v[0] + a.v[1].v[0], b.v[1].v[1] + a.v[1].v[1]])])
+b = M(v: [V(v: [b.v[0].v[0] + a.v[0].v[0], b.v[0].v[1] + a.v[0].v[1]]),
+      V(v: [b.v[1].v[0] + a.v[1].v[0], b.v[1].v[1] + a.v[1].v[1]])])
+echo b