From 279905ce3a1920b7ba09da678ac26cbbb9fbb886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Sat, 21 Mar 2020 00:07:52 +0100 Subject: [PATCH] fix #13417 --- compiler/transf.nim | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler/transf.nim b/compiler/transf.nim index c1af6c23f419..2bd64804e41e 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -554,14 +554,14 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto = # inline context. if formal.kind == tyTypeDesc: return paDirectMapping if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}: - case arg.kind - of nkStmtListExpr: - return paComplexOpenarray + case arg.skipHidden.kind of nkBracket: return paFastAsgnTakeTypeFromArg + of nkSym: + return paDirectMapping else: - return paDirectMapping # XXX really correct? - # what if ``arg`` has side-effects? + return paComplexOpenarray + case arg.kind of nkEmpty..nkNilLit: result = paDirectMapping @@ -569,14 +569,14 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto = result = putArgInto(arg[0], formal) of nkCurly, nkBracket: for i in 0..= ff.n.len: return result @@ -671,9 +671,8 @@ proc transformFor(c: PTransf, n: PNode): PNode = idNodeTablePut(newC.mapping, formal, arg) # XXX BUG still not correct if the arg has a side effect! of paComplexOpenarray: - let typ = newType(tySequence, formal.owner) - addSonSkipIntLit(typ, formal.typ[0]) - var temp = newTemp(c, typ, formal.info) + # arrays will deep copy here (pretty bad). + var temp = newTemp(c, arg.typ, formal.info) addVar(v, temp) stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg)) idNodeTablePut(newC.mapping, formal, temp)