diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arc/tarcmisc.nim | 52 | ||||
-rw-r--r-- | tests/ccgbugs/targ_lefttoright.nim | 70 |
2 files changed, 96 insertions, 26 deletions
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index e66d9a75f..b6d9d781d 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -15,6 +15,7 @@ destroyed: false (x: "8") (x: "9") (x: "10") +0 closed destroying variable ''' @@ -174,38 +175,37 @@ proc bug14495 = bug14495() -when false: - # bug #14396 - type - Spinny = ref object - t: ref int - text: string +# bug #14396 +type + Spinny = ref object + t: ref int + text: string - proc newSpinny*(): Spinny = - Spinny(t: new(int), text: "hello") +proc newSpinny*(): Spinny = + Spinny(t: new(int), text: "hello") - proc spinnyLoop(x: ref int, spinny: sink Spinny) = - echo x[] +proc spinnyLoop(x: ref int, spinny: sink Spinny) = + echo x[] - proc start*(spinny: sink Spinny) = - spinnyLoop(spinny.t, spinny) +proc start*(spinny: sink Spinny) = + spinnyLoop(spinny.t, spinny) - var spinner1 = newSpinny() - spinner1.start() +var spinner1 = newSpinny() +spinner1.start() - # bug #14345 +# bug #14345 - type - SimpleLoopB = ref object - children: seq[SimpleLoopB] - parent: SimpleLoopB +type + SimpleLoopB = ref object + children: seq[SimpleLoopB] + parent: SimpleLoopB - proc addChildLoop(self: SimpleLoopB, loop: SimpleLoopB) = - self.children.add loop +proc addChildLoop(self: SimpleLoopB, loop: SimpleLoopB) = + self.children.add loop - proc setParent(self: SimpleLoopB, parent: SimpleLoopB) = - self.parent = parent - self.parent.addChildLoop(self) +proc setParent(self: SimpleLoopB, parent: SimpleLoopB) = + self.parent = parent + self.parent.addChildLoop(self) - var l = SimpleLoopB() - l.setParent(l) +var l = SimpleLoopB() +l.setParent(l) diff --git a/tests/ccgbugs/targ_lefttoright.nim b/tests/ccgbugs/targ_lefttoright.nim new file mode 100644 index 000000000..b107b2327 --- /dev/null +++ b/tests/ccgbugs/targ_lefttoright.nim @@ -0,0 +1,70 @@ +discard """ + nimout: '''1,2 +2,3 +2,2 +1,2 +1,2 +2,2 +1,2 +''' + output: '''1,2 +2,3 +1,2 +2,2 +1,2 +1,2 +2,2 +1,2 +''' +""" + +template test = + proc say(a, b: int) = + echo a,",",b + + var a = 1 + say a, (a += 1; a) #1,2 + + var b = 1 + say (b += 1; b), (b += 1; b) #2,3 + + type C = object {.byRef.} + i: int + + proc say(a, b: C) = + echo a.i,",",b.i + + proc `+=`(x: var C, y: C) = x.i += y.i + + var c = C(i: 1) + when nimvm: #XXX: This would output 2,2 in the VM, which is wrong + discard + else: + say c, (c += C(i: 1); c) #1,2 + + proc sayVar(a: var int, b: int) = + echo a,",",b + + var d = 1 + sayVar d, (d += 1; d) #2,2 + + var e = 1 + say (addr e)[], (e += 1; e) #1,2 + + var f = 1 + say f, if false: f + else: f += 1; f #1,2 + + var g = 1 + say g + 1, if false: g + else: g += 1; g #2,2 + + proc `+=+`(x: var int, y: int): int = (inc(x, y); x) + + var h = 1 + say h, h +=+ 1 # 1,2 + +test + +static: + test |