Nim/tests/destructor/tmisc_destructors.nim
Andreas Rumpf fb641483f0
arc optimizations (#13325)
* scope based destructors
* handle 'or' and 'and' expressions properly, see the new test arc/tcontrolflow.nim
* make this branch mergable, logic is disabled for now
2020-03-18 16:57:34 +01:00

41 lines
623 B
Nim

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 test(): auto =
var a, b: Foo
return (a, b, Foo(boo: 5))
var (a, b, _) = 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()