import typetraits as tt
type TMyTuple = tuple[a, b: int, c: string]
proc foo(i: int): int = i + 2
echo "name = ", tt.name(TMyTuple) # prints 'name = TMyTuple'
echo "name = ", tt.name(type(foo)) # compiler error in semmagic.nim semTypeTraits()
I know why I get the error only for the proc. The tuple gets correctly parsed as an nkSym and skType. However, the proc comes in as a tree of nkTypeOfExpr / nkPar / nkIdent rather than as a node of nkSym and skProc, which is what I would expect.
Can someone help shed some light on why this is the case?
Looking through the AST when in semTypeTraits() I noticed that any nkSym PNodes and nkIdent PNodes will report sonsLen() of 4480072496 and 4480076040, respectively. I noticed this behavior on the master branch as well as the devel branch.
Those seem high compared to all the other PNodes which have 0 to 3 number of sons. Is this a bug or expected?
---type = [k = tyTypeDesc, basetypes = 1, n=nil]
-------type = [k = tyProc, basetypes = 2]
-----------PNode, kind = [nkFormalParams], type = [], sonsLen = 2
-------------PNode, kind = [nkArgList], type = [k = tyInt, s_n = int, s_k = skType], sonsLen = 4
---------------PNode, kind = [nkArgList], type = [], sonsLen = 0
---------------PNode = nil
---------------PNode = nil
---------------PNode, kind = [nkArgList], type = [], sonsLen = 0
-------------PNode, kind = [nkSym], type = [k = tyInt, s_n = int, s_k = skType], sym = [i,skParam]
-----------type = [k = tyInt, s_n = int, s_k = skType, basetypes = 0, n=nil]
-----------type = [k = tyInt, s_n = int, s_k = skType, basetypes = 0, n=nil]
Yeah, I see the exception now when compiling it in debug mode. Good to know.