I'm new to nim and I don't understand why this doesn't work.
type
Thing = ref object
value: int
proc function(thing: Thing not nil): void =
discard
proc not_nil*[T](obj: T): T not nil =
if obj.isNil:
assert false
else:
result = obj
let t = Thing()
function(not_nil(t))
not_nil.nim(16, 17) Error: cannot prove 'not_nil(t)' is not nil
Is this a bug? Many thanks.
try:
type
ThingObj = object
value: int
Thing = ref ThingObj not nil
proc function(thing: Thing): void =
discard
proc not_nil*[T](obj: T): T =
if obj.isNil:
assert false
else:
result = obj
let t = Thing()
function(not_nil(t))