diff options
author | Zahary Karadjov <zahary@gmail.com> | 2020-03-30 00:49:42 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-04-01 19:38:44 +0200 |
commit | e63b673ce2557bcc3189bd5917b35327253b4c1b (patch) | |
tree | 6f6e3b5fc812a9cede2226e78ed9eb7adeaea080 /tests/constructors | |
parent | 06438ed1431ee8ad3ae2eda9dcb7fbe64739329a (diff) | |
download | Nim-e63b673ce2557bcc3189bd5917b35327253b4c1b.tar.gz |
Fix https://github.com/nim-lang/Nim/issues/4907
Diffstat (limited to 'tests/constructors')
-rw-r--r-- | tests/constructors/tinvalid_construction.nim | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/constructors/tinvalid_construction.nim b/tests/constructors/tinvalid_construction.nim index c17e2123c..6716bfb45 100644 --- a/tests/constructors/tinvalid_construction.nim +++ b/tests/constructors/tinvalid_construction.nim @@ -267,4 +267,43 @@ block: of C: r: range[1..1] # DateTime # Fine to not initialize 'r' because this is implicitly initialized and known to be branch 'A'. - let someThing = Thing() + var x = Thing() + discard x + +block: + # https://github.com/nim-lang/Nim/issues/4907 + type + Foo = ref object + Bar = object + + Thing[A, B] = ref object + a: A not nil + b: ref B + c: ref B not nil + + proc allocNotNil(T: typedesc): T not nil = + new result + + proc mutateThing(t: var Thing[Foo, Bar]) = + let fooNotNil = allocNotNil(Foo) + var foo: Foo + + let barNotNil = allocNotNil(ref Bar) + var bar: ref Bar + + t.a = fooNotNil + t.b = bar + t.b = barNotNil + t.c = barNotNil + + reject: + t.a = foo + + reject: + t.c = bar + + var thing = Thing[Foo, Bar](a: allocNotNil(Foo), + b: allocNotNil(ref Bar), + c: allocNotNil(ref Bar)) + mutateThing thing + |