I'm trying to call function on objects of specific type from the sequence, but compiler complains.
How to fix that? I need to get text
property from the TextDoc
objects.
type
DocItem = object of RootObj
tags: seq[string]
TextDoc = object of DocItem
text: string
TodoDoc = object of DocItem
todo: string
var docs: seq[ref DocItem]
proc to_ref[T](o: T): ref T =
result.new
result[] = o
docs.add TextDoc(text: "some doc").to_ref
docs.add TodoDoc(todo: "some todo").to_ref
for d in docs:
if d of TextDoc:
echo d.text
Error
Error: undeclared field: 'text'