It is not possible, because Nim is a statically strongly typed language. It is 
not possible to determine exactly the type of your return value.

However, you could do something like this:
    
    
    import std/random
    
    randomize()
    
    type Parent = ref object of RootRef
    type ChildA = ref object of Parent
    type ChildB = ref object of Parent
    
    var a = ChildA()
    var b = ChildB()
    
    proc foo(t, u: Parent): Parent =
        if rand(1..10) > 5:
            t
        else:
            u
    
    var res = foo(a, b)
    if res of ChildA:
      echo "ChildA"
    else:
      echo "ChildB"
    
    
    Run

Reply via email to