diff options
author | cooldome <ariabushenko@gmail.com> | 2020-11-16 11:39:28 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 11:39:28 +0000 |
commit | a4d02f591c685b261a41a7b9b51aaba05c542499 (patch) | |
tree | b92e5b5e22a6600586236cf347c74dcd465c2783 /tests/arc/t14383.nim | |
parent | fc735e4b08d9401dc2b22a1432d1231fa18b4a4f (diff) | |
download | Nim-a4d02f591c685b261a41a7b9b51aaba05c542499.tar.gz |
fix #15910 (#15984)
* fix #15910 * produce op of op is nil * Trigger build
Diffstat (limited to 'tests/arc/t14383.nim')
-rw-r--r-- | tests/arc/t14383.nim | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/arc/t14383.nim b/tests/arc/t14383.nim index 834c50def..7c63f7333 100644 --- a/tests/arc/t14383.nim +++ b/tests/arc/t14383.nim @@ -4,6 +4,21 @@ discard """ hello hello @["a", "b"] +--------------------- +plain: +destroying: ('first', 42) +destroying: ('second', 20) +destroying: ('third', 12) + +Option[T]: +destroying: ('first', 42) +destroying: ('second', 20) +destroying: ('third', 12) + +seq[T]: +destroying: ('first', 42) +destroying: ('second', 20) +destroying: ('third', 12) ''' """ @@ -47,4 +62,53 @@ proc freeJVMObject(o: JVMObject) = proc fromJObject(T: typedesc[JVMObject]): T = result.new(cast[proc(r: T) {.nimcall.}](freeJVMObject)) -discard JVMObject.fromJObject() \ No newline at end of file +discard JVMObject.fromJObject() + + +#------------------------------------------------------------------------------ +# Issue #15910 +#------------------------------------------------------------------------------ + +import options + +type + Thing = object + name: string + age: int + +proc `=destroy`(thing: var Thing) = + if thing.name != "": + echo "destroying: ('", thing.name, "', ", thing.age, ")" + `=destroy`(thing.name) + `=destroy`(thing.age) + +proc plain() = + var t = Thing(name: "first", age: 42) + t = Thing(name: "second", age: 20) + t = Thing() + let u = Thing(name: "third", age: 12) + +proc optionT() = + var t = Thing(name: "first", age: 42).some + t = Thing(name: "second", age: 20).some + t = none(Thing) + let u = Thing(name: "third", age: 12).some + +proc seqT() = + var t = @[Thing(name: "first", age: 42)] + t = @[Thing(name: "second", age: 20)] + t = @[] + let u = @[Thing(name: "third", age: 12)] + +echo "---------------------" +echo "plain:" +plain() +echo() + +echo "Option[T]:" +optionT() +echo() + +echo "seq[T]:" +seqT() +echo() \ No newline at end of file |