summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2017-04-30 22:28:20 +0300
committerZahary Karadjov <zahary@gmail.com>2017-04-30 22:28:20 +0300
commit2a3455259618723b9a748b16e2fccf2a06b0c9cb (patch)
tree04a97ab1071f495e070728d16cc77e17e3578331
parent622100adb6deb75cfb0fad4e4e94af9f0d7a232c (diff)
downloadNim-2a3455259618723b9a748b16e2fccf2a06b0c9cb.tar.gz
fix 5756
-rw-r--r--compiler/ccgexprs.nim2
-rw-r--r--tests/generics/tgenericconst.nim39
2 files changed, 40 insertions, 1 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index f981f9595..f2c6f076c 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2203,7 +2203,7 @@ proc getNullValueAux(p: BProc; obj, cons: PNode, result: var Rope) =
     let field = obj.sym
     for i in 1..<cons.len:
       if cons[i].kind == nkExprColonExpr:
-        if cons[i][0].sym == field:
+        if cons[i][0].sym.name == field.name:
           result.add genConstExpr(p, cons[i][1])
           return
       elif i == field.position:
diff --git a/tests/generics/tgenericconst.nim b/tests/generics/tgenericconst.nim
new file mode 100644
index 000000000..3c86888df
--- /dev/null
+++ b/tests/generics/tgenericconst.nim
@@ -0,0 +1,39 @@
+discard """
+output: '''
+@[1, 2]
+@[3, 4]
+1
+'''
+"""
+
+# https://github.com/nim-lang/Nim/issues/5756
+
+type
+  Vec*[N : static[int]] = object
+    x: int
+    arr*: array[N, int32]
+
+  Mat*[M,N: static[int]] = object
+    x: int
+    arr*: array[M, Vec[N]]
+
+proc vec2*(x,y:int32) : Vec[2] =
+  result.arr = [x,y]
+  result.x = 10
+
+proc mat2*(a,b: Vec[2]): Mat[2,2] =
+  result.arr = [a,b]
+  result.x = 20
+
+const M = mat2(vec2(1, 2), vec2(3, 4))
+
+let m1 = M
+echo @(m1.arr[0].arr)
+echo @(m1.arr[1].arr)
+
+proc foo =
+  let m2 = M
+  echo m1.arr[0].arr[0]
+
+foo()
+