summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMatthew Baulch <baulch.matt@gmail.com>2016-07-14 20:51:40 +1000
committerMatthew Baulch <baulch.matt@gmail.com>2016-07-14 20:51:40 +1000
commitde41649b0e044729583e8c5061593bc7ebff594d (patch)
tree074a4ddbe55a49198b40b5b44d2d651093ca4453
parent813828f6907ce05756145c57bc6dd4758ffb2a7e (diff)
downloadNim-de41649b0e044729583e8c5061593bc7ebff594d.tar.gz
Use target field types in tuple conversions.
-rw-r--r--compiler/semexprs.nim4
-rw-r--r--tests/tuples/tconver_tuple.nim19
2 files changed, 23 insertions, 0 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 17feab85d..5a27d8621 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -198,6 +198,10 @@ proc semConv(c: PContext, n: PNode): PNode =
       # separate proc from fitNode?
       if op.kind == nkSym and op.sym.isGenericRoutine:
         result.sons[1] = fitNode(c, result.typ, result.sons[1])
+      elif op.kind == nkPar and targetType.kind == tyTuple:
+        # Set type of each field in case any have type tyEmpty (eg. `@[]`)
+        for i in 0..<op.sons.len:
+          op.sons[i][1].typ = targetType.sons[i]
     of convNotNeedeed:
       message(n.info, hintConvFromXtoItselfNotNeeded, result.typ.typeToString)
     of convNotLegal:
diff --git a/tests/tuples/tconver_tuple.nim b/tests/tuples/tconver_tuple.nim
new file mode 100644
index 000000000..b37be968a
--- /dev/null
+++ b/tests/tuples/tconver_tuple.nim
@@ -0,0 +1,19 @@
+# Bug 4479
+
+type
+  MyTuple = tuple
+    num: int
+    strings: seq[string]
+    ints: seq[int]
+
+var foo = MyTuple((
+  num: 7,
+  strings: @[],
+  ints: @[],
+))
+
+var bar = (
+  num: 7,
+  strings: @[],
+  ints: @[],
+).MyTuple