Don't allow 'var x: T' for objects that require initialization

This commit is contained in:
Zahary Karadjov 2020-03-27 20:22:37 +02:00 • committed by Andreas Rumpf
commit 05a0ec4adb
4 changed files with 63 additions and 37 deletions

View file

@ -125,10 +125,14 @@ accept PartialRequiresInit(a: 10, b: "x")
accept PartialRequiresInit(a: 20)
reject PartialRequiresInit(b: "x")
reject PartialRequiresInit()
reject:
var obj: PartialRequiresInit
accept FullRequiresInit(a: 10, b: 20)
reject FullRequiresInit(a: 10)
reject FullRequiresInit(b: 20)
reject:
var obj: FullRequiresInit
accept FullRequiresInitWithParent(a: notNilRef, b: notNilRef, c: notNilRef, e: 10, d: 20)
accept FullRequiresInitWithParent(a: notNilRef, b: notNilRef, c: nil, e: 10, d: 20)
@ -136,9 +140,13 @@ reject FullRequiresInitWithParent(a: notNilRef, b: nil, c: nil, e: 10, d: 20) #
reject FullRequiresInitWithParent(a: notNilRef, b: notNilRef, e: 10, d: 20) # c should not be missing
reject FullRequiresInitWithParent(a: notNilRef, b: notNilRef, c: nil, e: 10) # d should not be missing
reject FullRequiresInitWithParent()
reject:
var obj: FullRequiresInitWithParent
# this will be accepted, because the false outer branch will be taken and the inner A branch
accept TNestedChoices()
accept:
var obj: TNestedChoices
# but if we supply a run-time value for the inner branch, the compiler won't be able to prove
# that the notnil field was initialized