@mrsekut First, your code has a problem by passing a small 'a' but `parseStatement` expects a capital 'A' or 'B'.
I'm a bit confused by your approach but I'll try to help anyway. type A = ref object of RootObj name: string value: string B = ref object of RootObj name: string C = ref object of RootObj flg: string None = ref object of RootObj proc parseStatement(self: C): ref RootObj = case self.flg of "A": result = A(name: "a", value: "val") of "B": result = B(name: "b") else: result = cast[None](0) # now, test it let c = C(flg: "A") let resc = c.parseStatement() echo resc.repr let d = C(flg: "?") # unknown/invalid let resd = d.parseStatement() echo resd.repr let e = C(flg: "B") # unknown/invalid let rese = e.parseStatement() echo rese.repr Run works and is probably what you wanted. Side note re. small vs capital 'a' etc.: You might find it interesting to know that Nim's `case` accepts multiple options or ranges, too. So the follwing might be closer to what you had in mind: proc parseStatement(self: C): ref RootObj = case self.flg of "A", "a": result = A(name: "a", value: "val") of "B","b": result = B(name: "b") else: result = cast[None](0) # now, test it Run