Skip to content

Commit

Permalink
Add testcase for nim-lang#14601 (nim-lang#15677)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber authored and mildred committed Jan 11, 2021
1 parent e0b1aaf commit d054d5e
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/destructor/tdestructor3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,48 @@ proc test2() =
echo "---------------"
echo "app begin"
test2()
echo "app end"
echo "app end"

# bug #14601

when true: # D20200607T202043
type Foo2 = object
x: int
x2: array[10, int]

type Vec = object
vals: seq[Foo2]

proc `=destroy`*(a: var Foo2) {.inline.} =
discard

proc initFoo2(x: int): Foo2 = Foo2(x: x)

proc add2(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2`
v.vals.add a

proc add3(v: var Vec, a: Foo2) = # ditto with `a: sink Foo2`
v.vals = @[a]

proc add4(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2`
v.vals.add a

proc add5(v: var Vec, a: sink Foo2) = # ditto with `a: sink Foo2`
v.vals = @[a]

proc main2()=
var a: Vec
var b = Foo2(x: 10)
a.add2 b # ok
a.vals.add Foo2(x: 10) # ok
a.add2 initFoo2(x = 10) # ok
a.add2 Foo2(x: 10) # bug
a.add3 initFoo2(x = 10) # ok
a.add3 Foo2(x: 10) # bug
a.add4 initFoo2(x = 10) # ok
a.add4 Foo2(x: 10) # bug
a.add5 initFoo2(x = 10) # ok
a.add5 Foo2(x: 10) # bug
main2()


0 comments on commit d054d5e

Please sign in to comment.