mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #2659
This commit is contained in:
@@ -515,7 +515,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||
line(p, cpsStmts, pl)
|
||||
|
||||
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||
if e.sons[0].typ.callConv == ccClosure:
|
||||
if e.sons[0].typ.skipTypes({tyGenericInst}).callConv == ccClosure:
|
||||
genClosureCall(p, nil, e, d)
|
||||
elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags:
|
||||
genInfixCall(p, nil, e, d)
|
||||
@@ -528,7 +528,7 @@ proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||
if d.s == onStack and containsGarbageCollectedRef(d.t): keepAlive(p, d)
|
||||
|
||||
proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||
if ri.sons[0].typ.callConv == ccClosure:
|
||||
if ri.sons[0].typ.skipTypes({tyGenericInst}).callConv == ccClosure:
|
||||
genClosureCall(p, le, ri, d)
|
||||
elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags:
|
||||
genInfixCall(p, le, ri, d)
|
||||
|
||||
@@ -207,7 +207,7 @@ proc newAsgnStmt(le, ri: PNode, info: TLineInfo): PNode =
|
||||
result.sons[0] = le
|
||||
result.sons[1] = ri
|
||||
|
||||
proc makeClosure(prc: PSym; env: PNode; info: TLineInfo): PNode =
|
||||
proc makeClosure*(prc: PSym; env: PNode; info: TLineInfo): PNode =
|
||||
result = newNodeIT(nkClosure, info, prc.typ)
|
||||
result.add(newSymNode(prc))
|
||||
if env == nil:
|
||||
|
||||
@@ -114,6 +114,9 @@ proc transformSymAux(c: PTransf, n: PNode): PNode =
|
||||
if n.sym.kind == skIterator and n.sym.typ.callConv == ccClosure:
|
||||
if c.tooEarly: return n
|
||||
else: return liftIterSym(n, getCurrOwner(c))
|
||||
#elif n.sym.kind in {skVar, skLet} and n.sym.typ.callConv == ccClosure:
|
||||
# echo n.info, " come heer for ", c.tooEarly
|
||||
# if not c.tooEarly: return makeClosure(n.sym, nil, n.info)
|
||||
var b: PNode
|
||||
var tc = c.transCon
|
||||
if sfBorrow in n.sym.flags and n.sym.kind in routineKinds:
|
||||
|
||||
28
tests/ccgbugs/tgeneric_closure.nim
Normal file
28
tests/ccgbugs/tgeneric_closure.nim
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
# bug 2659
|
||||
|
||||
type
|
||||
GenProcType[T,U] = proc(x:T, y:var U)
|
||||
IntProcType = proc(x:int, y:var int)
|
||||
|
||||
proc mult(x:int, y:var int) =
|
||||
y = 2 * x
|
||||
|
||||
when isMainModule:
|
||||
|
||||
var input = 1
|
||||
var output = 0
|
||||
|
||||
var someIntProc:IntProcType = mult
|
||||
var someGenProc:GenProcType[int,int] = mult
|
||||
|
||||
mult(input, output)
|
||||
echo output
|
||||
|
||||
someIntProc(input, output)
|
||||
echo output
|
||||
|
||||
# Uncommenting causes an error in the C compiler.
|
||||
someGenProc(input, output)
|
||||
echo output
|
||||
Reference in New Issue
Block a user