parent
64ffa17f0f
commit
a5f02cac85
2 changed files with 31 additions and 11 deletions
|
|
@ -554,14 +554,14 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
||||||
# inline context.
|
# inline context.
|
||||||
if formal.kind == tyTypeDesc: return paDirectMapping
|
if formal.kind == tyTypeDesc: return paDirectMapping
|
||||||
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
|
if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
|
||||||
case arg.kind
|
case arg.skipHidden.kind
|
||||||
of nkStmtListExpr:
|
|
||||||
return paComplexOpenarray
|
|
||||||
of nkBracket:
|
of nkBracket:
|
||||||
return paFastAsgnTakeTypeFromArg
|
return paFastAsgnTakeTypeFromArg
|
||||||
|
of nkSym:
|
||||||
|
return paDirectMapping
|
||||||
else:
|
else:
|
||||||
return paDirectMapping # XXX really correct?
|
return paComplexOpenarray
|
||||||
# what if ``arg`` has side-effects?
|
|
||||||
case arg.kind
|
case arg.kind
|
||||||
of nkEmpty..nkNilLit:
|
of nkEmpty..nkNilLit:
|
||||||
result = paDirectMapping
|
result = paDirectMapping
|
||||||
|
|
@ -644,7 +644,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
|
||||||
# generate access statements for the parameters (unless they are constant)
|
# generate access statements for the parameters (unless they are constant)
|
||||||
pushTransCon(c, newC)
|
pushTransCon(c, newC)
|
||||||
for i in 1..<call.len:
|
for i in 1..<call.len:
|
||||||
var arg = transform(c, call[i])
|
let arg = transform(c, call[i])
|
||||||
let ff = skipTypes(iter.typ, abstractInst)
|
let ff = skipTypes(iter.typ, abstractInst)
|
||||||
# can happen for 'nim check':
|
# can happen for 'nim check':
|
||||||
if i >= ff.n.len: return result
|
if i >= ff.n.len: return result
|
||||||
|
|
@ -671,9 +671,8 @@ proc transformFor(c: PTransf, n: PNode): PNode =
|
||||||
idNodeTablePut(newC.mapping, formal, arg)
|
idNodeTablePut(newC.mapping, formal, arg)
|
||||||
# XXX BUG still not correct if the arg has a side effect!
|
# XXX BUG still not correct if the arg has a side effect!
|
||||||
of paComplexOpenarray:
|
of paComplexOpenarray:
|
||||||
let typ = newType(tySequence, formal.owner)
|
# arrays will deep copy here (pretty bad).
|
||||||
addSonSkipIntLit(typ, formal.typ[0])
|
var temp = newTemp(c, arg.typ, formal.info)
|
||||||
var temp = newTemp(c, typ, formal.info)
|
|
||||||
addVar(v, temp)
|
addVar(v, temp)
|
||||||
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
|
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
|
||||||
idNodeTablePut(newC.mapping, formal, temp)
|
idNodeTablePut(newC.mapping, formal, temp)
|
||||||
|
|
|
||||||
|
|
@ -213,3 +213,24 @@ block t2023_objiter:
|
||||||
|
|
||||||
var o = init()
|
var o = init()
|
||||||
echo(o.iter())
|
echo(o.iter())
|
||||||
|
|
||||||
|
block:
|
||||||
|
# bug #13417
|
||||||
|
|
||||||
|
var effectCounterP1 = 0
|
||||||
|
|
||||||
|
proc p1(): seq[int] =
|
||||||
|
inc effectCounterP1
|
||||||
|
@[1,2]
|
||||||
|
|
||||||
|
iterator ip1(v: openArray[int]): auto =
|
||||||
|
for x in v:
|
||||||
|
yield x
|
||||||
|
|
||||||
|
var effectCounterLoop = 0
|
||||||
|
|
||||||
|
for x in ip1(p1()):
|
||||||
|
inc effectCounterLoop
|
||||||
|
|
||||||
|
doAssert effectCounterP1 == 1
|
||||||
|
doAssert effectCounterLoop == 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue