From a4d02f591c685b261a41a7b9b51aaba05c542499 Mon Sep 17 00:00:00 2001 From: cooldome Date: Mon, 16 Nov 2020 11:39:28 +0000 Subject: fix #15910 (#15984) * fix #15910 * produce op of op is nil * Trigger build --- tests/arc/t14383.nim | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'tests') 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 -- cgit 1.4.1-2-gfad0