parent
2678fa679a
commit
64e1408920
2 changed files with 40 additions and 7 deletions
|
|
@ -555,17 +555,22 @@ proc transformConv(c: PTransf, n: PNode): PTransNode =
|
||||||
|
|
||||||
type
|
type
|
||||||
TPutArgInto = enum
|
TPutArgInto = enum
|
||||||
paDirectMapping, paFastAsgn, paVarAsgn, paComplexOpenarray
|
paDirectMapping, paFastAsgn, paFastAsgnTakeTypeFromArg
|
||||||
|
paVarAsgn, paComplexOpenarray
|
||||||
|
|
||||||
proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
|
||||||
# This analyses how to treat the mapping "formal <-> arg" in an
|
# This analyses how to treat the mapping "formal <-> arg" in an
|
||||||
# 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}:
|
||||||
if arg.kind == nkStmtListExpr:
|
case arg.kind
|
||||||
|
of nkStmtListExpr:
|
||||||
return paComplexOpenarray
|
return paComplexOpenarray
|
||||||
return paDirectMapping # XXX really correct?
|
of nkBracket:
|
||||||
# what if ``arg`` has side-effects?
|
return paFastAsgnTakeTypeFromArg
|
||||||
|
else:
|
||||||
|
return paDirectMapping # XXX really correct?
|
||||||
|
# what if ``arg`` has side-effects?
|
||||||
case arg.kind
|
case arg.kind
|
||||||
of nkEmpty..nkNilLit:
|
of nkEmpty..nkNilLit:
|
||||||
result = paDirectMapping
|
result = paDirectMapping
|
||||||
|
|
@ -645,12 +650,15 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
# can happen for 'nim check':
|
# can happen for 'nim check':
|
||||||
if i >= ff.n.len: return result
|
if i >= ff.n.len: return result
|
||||||
var formal = ff.n.sons[i].sym
|
var formal = ff.n.sons[i].sym
|
||||||
case putArgInto(arg, formal.typ)
|
let pa = putArgInto(arg, formal.typ)
|
||||||
|
case pa
|
||||||
of paDirectMapping:
|
of paDirectMapping:
|
||||||
idNodeTablePut(newC.mapping, formal, arg)
|
idNodeTablePut(newC.mapping, formal, arg)
|
||||||
of paFastAsgn:
|
of paFastAsgn, paFastAsgnTakeTypeFromArg:
|
||||||
var t = formal.typ
|
var t = formal.typ
|
||||||
if formal.ast != nil and formal.ast.typ.destructor != nil and t.destructor == nil:
|
if pa == paFastAsgnTakeTypeFromArg:
|
||||||
|
t = arg.typ
|
||||||
|
elif formal.ast != nil and formal.ast.typ.destructor != nil and t.destructor == nil:
|
||||||
t = formal.ast.typ # better use the type that actually has a destructor.
|
t = formal.ast.typ # better use the type that actually has a destructor.
|
||||||
elif t.destructor == nil and arg.typ.destructor != nil:
|
elif t.destructor == nil and arg.typ.destructor != nil:
|
||||||
t = arg.typ
|
t = arg.typ
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ dflfdjkl__abcdefgasfsgdfgsgdfggsdfasdfsafewfkljdsfajsdf
|
||||||
kgdchlfniambejop
|
kgdchlfniambejop
|
||||||
fjpmholcibdgeakn
|
fjpmholcibdgeakn
|
||||||
2.0
|
2.0
|
||||||
|
a:1
|
||||||
|
a:2
|
||||||
|
a:3
|
||||||
|
ret:
|
||||||
|
ret:1
|
||||||
|
ret:12
|
||||||
|
123
|
||||||
'''
|
'''
|
||||||
joinable: false
|
joinable: false
|
||||||
"""
|
"""
|
||||||
|
|
@ -557,3 +564,21 @@ block arrayLiterals:
|
||||||
doAssert [1: 2][1] == 2
|
doAssert [1: 2][1] == 2
|
||||||
doAssert [-1'i8: 2][-1] == 2
|
doAssert [-1'i8: 2][-1] == 2
|
||||||
doAssert [-1'i8: 2, 3, 4, 5].Idx is range[-1'i8..2'i8]
|
doAssert [-1'i8: 2, 3, 4, 5].Idx is range[-1'i8..2'i8]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# bug #8316
|
||||||
|
|
||||||
|
proc myAppend[T](a:T):string=
|
||||||
|
echo "a:", a
|
||||||
|
return $a
|
||||||
|
|
||||||
|
template append2*(args: varargs[string, myAppend]): string =
|
||||||
|
var ret:string
|
||||||
|
for a in args:
|
||||||
|
echo "ret:", ret
|
||||||
|
ret.add(a)
|
||||||
|
ret
|
||||||
|
|
||||||
|
let foo = append2("1", "2", "3")
|
||||||
|
echo foo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue