summary refs log tree commit diff stats
path: root/tests/destructor/tmisc_destructors.nim
blob: 082cb0f785d1cefef63de694c47683f31a9d9789 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
discard """
  output: '''@[0]
@[1]
@[2]
@[3]'''
  joinable: false
"""

# bug #6434

type
  Foo* = object
    boo: int

var sink_counter = 0
var assign_counter = 0

proc `=sink`(dest: var Foo, src: Foo) =
  sink_counter.inc

proc `=`(dest: var Foo, src: Foo) =
  assign_counter.inc

proc createFoo(): Foo = Foo(boo: 0)

proc test(): auto =
  var a, b = createFoo()
  return (a, b, Foo(boo: 5))

var (ag, bg, _) = test()

doAssert assign_counter == 0
doAssert sink_counter == 0

# bug #11510
proc main =
  for i in 0 ..< 4:
    var buffer: seq[int] # = @[] # uncomment to make it work
    # var buffer: string # also this is broken
    buffer.add i
    echo buffer

main()