diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-11-05 21:00:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 14:00:08 +0100 |
commit | a8af664e8ba8672e736c72971a18c0e00ba9b086 (patch) | |
tree | aa4a90065f3f423dbbf042b6564958e610f56d47 | |
parent | cae92f670a00ca1a343667dfeb5dfef208086f21 (diff) | |
download | Nim-a8af664e8ba8672e736c72971a18c0e00ba9b086.tar.gz |
fix #15463 (#15831)
-rw-r--r-- | compiler/lowerings.nim | 1 | ||||
-rw-r--r-- | compiler/vmgen.nim | 2 | ||||
-rw-r--r-- | tests/vm/tswap.nim | 12 |
3 files changed, 13 insertions, 2 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index 40d61b779..e9e704075 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -138,6 +138,7 @@ proc lowerSwap*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: PSym): PNod var temp = newSym(skVar, getIdent(g.cache, genPrefix), nextId(idgen), 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) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 61c7fefd9..bcb7faa47 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -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, c.idgen, if c.prc == nil: c.module else: c.prc.sym)) + c.gen(lowerSwap(c.graph, n, c.idgen, 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) diff --git a/tests/vm/tswap.nim b/tests/vm/tswap.nim index 4243b5a71..bdbe5528c 100644 --- a/tests/vm/tswap.nim +++ b/tests/vm/tswap.nim @@ -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 |