Skip to content

Commit

Permalink
fix #16020; fix #16780
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Jun 16, 2022
1 parent 2bffb86 commit 3cdcae2
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion tests/vm/tmisc_vm.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
discard """
targets: "c js"
output: '''
[127, 127, 0, 255][127, 127, 0, 255]
(data: 1)
(2, 1)
(2, 1)
(2, 1)
(f0: 5)
'''
nimout: '''caught Exception
Expand All @@ -26,6 +31,10 @@ z3 a: (lo: 3)
x1 a: (lo: 3)
x2 a: (lo: 6)
x3 a: (lo: 0)
(2, 1)
(2, 1)
(2, 1)
(f0: 5)
'''
"""
import std/sets
Expand Down Expand Up @@ -368,4 +377,53 @@ static:
var x = Stuint(lo: high(uint64))
var y = Stuint(lo: 12)

powmod(x, y)
powmod(x, y)

# bug #16780
when true:
template swap*[T](a, b: var T) =
var a2 = addr(a)
var b2 = addr(b)
var aOld = a2[]
a2[] = b2[]
b2[] = aOld

proc rather =
block:
var a = 1
var b = 2
swap(a, b)
echo (a,b)

block:
type Foo = ref object
x: int
var a = Foo(x:1)
var b = Foo(x:2)
swap(a, b)
echo (a.x, b.x)

block:
type Foo = object
x: int
var a = Foo(x:1)
var b = Foo(x:2)
swap(a, b)
echo (a.x,b.x)

static: rather()
rather()

# bug #16020
when true:
block:
type Foo = object
f0: int
proc main=
var f = Foo(f0: 3)
var f2 = f.addr
f2[].f0 += 1
f2.f0 += 1
echo f
static: main()
main()

0 comments on commit 3cdcae2

Please sign in to comment.