(cherry picked from commit a8af664e8b)
This commit is contained in:
flywind
2020-11-05 21:00:08 +08:00
committed by narimiran
parent 5da17acfce
commit 64ded4a51f
3 changed files with 13 additions and 2 deletions

View File

@@ -136,6 +136,7 @@ proc lowerSwap*(g: ModuleGraph; n: PNode; owner: PSym): PNode =
var temp = newSym(skVar, getIdent(g.cache, genPrefix), owner, n.info, owner.options)
temp.typ = n[1].typ
incl(temp.flags, sfFromGeneric)
incl(temp.flags, sfGenSym)
var v = newNodeI(nkVarSection, n.info)
let tempAsNode = newSymNode(temp)

View File

@@ -1122,7 +1122,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
c.freeTemp(d)
of mSwap:
unused(c, n, dest)
c.gen(lowerSwap(c.graph, n, if c.prc == nil: c.module else: c.prc.sym))
c.gen(lowerSwap(c.graph, n, if c.prc == nil or c.prc.sym == nil: c.module else: c.prc.sym))
of mIsNil: genUnaryABC(c, n, dest, opcIsNil)
of mParseBiggestFloat:
if dest < 0: dest = c.getTemp(n.typ)

View File

@@ -3,7 +3,9 @@ nimout: '''
x.data = @[10]
y = @[11]
x.data = @[11]
y = @[10]'''
y = @[10]
@[3, 2, 1]
'''
"""
# bug #2946
@@ -22,3 +24,11 @@ proc testSwap(): int {.compiletime.} =
result = 99
const something = testSwap()
# bug #15463
block:
static:
var s = @[1, 2, 3]
swap(s[0], s[2])
echo s