From 4f3d309fb0d17e52644029f4c593cd670516655a Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 29 Mar 2020 20:31:37 +0300 Subject: Perform nil checks during object construction and within compiles() Close https://github.com/nim-lang/Nim/issues/6494 --- tests/constructors/tinvalid_construction.nim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/constructors') diff --git a/tests/constructors/tinvalid_construction.nim b/tests/constructors/tinvalid_construction.nim index eb84c53c8..e6fdbcb85 100644 --- a/tests/constructors/tinvalid_construction.nim +++ b/tests/constructors/tinvalid_construction.nim @@ -75,7 +75,7 @@ type var x = D var nilRef: TRefObj -var notNilRef = TRefObj(x: 20) +let notNilRef = TRefObjNotNil(x: 20) proc makeHasNotNils: ref THasNotNils = (ref THasNotNils)(a: TRefObj(x: 10), @@ -102,8 +102,7 @@ reject TObj(a: 10, f: "") # conflicting fields accept TObj(choice: E, e1: TRefObj(x: 10), e2: 10) accept THasNotNils(a: notNilRef, b: notNilRef, c: nilRef) -# XXX: the "not nil" logic in the compiler is not strong enough to catch this one yet: -# reject THasNotNils(a: notNilRef, b: nilRef, c: nilRef) +reject THasNotNils(a: notNilRef, b: nilRef, c: nilRef) # `b` shouldn't be nil reject THasNotNils(b: notNilRef, c: notNilRef) # there is a missing not nil field reject THasNotNils() # again, missing fields accept THasNotNils(a: notNilRef, b: notNilRef) # it's OK to omit a non-mandatory field -- cgit 1.4.1-2-gfad0