From de41649b0e044729583e8c5061593bc7ebff594d Mon Sep 17 00:00:00 2001 From: Matthew Baulch Date: Thu, 14 Jul 2016 20:51:40 +1000 Subject: [PATCH 1/3] Use target field types in tuple conversions. --- compiler/semexprs.nim | 4 ++++ tests/tuples/tconver_tuple.nim | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/tuples/tconver_tuple.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 17feab85d7..5a27d86218 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.. Date: Thu, 14 Jul 2016 21:24:39 +1000 Subject: [PATCH 2/3] Fix: Correctly (and more efficiently) handle non-tuple conversions. --- compiler/semexprs.nim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5a27d86218..3208403d48 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -198,8 +198,9 @@ 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. `@[]`) + elif op.kind == nkPar and targetType.kind == tyTuple and + op.sons.len > 0 and op.sons[0].kind == nkExprColonExpr: + # Tuple conversion: set field types in case any are tyEmpty (eg. `@[]`) for i in 0.. Date: Fri, 15 Jul 2016 20:36:11 +1000 Subject: [PATCH 3/3] Handle tuples with unnamed fields, symbols, and more. Less duplication. --- compiler/semexprs.nim | 7 ++----- tests/tuples/tconver_tuple.nim | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 3208403d48..96c80c64ea 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -198,11 +198,8 @@ 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 and - op.sons.len > 0 and op.sons[0].kind == nkExprColonExpr: - # Tuple conversion: set field types in case any are tyEmpty (eg. `@[]`) - for i in 0..