@@ -42,7 +42,7 @@ proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
4242 result .info = info
4343
4444proc mapTypeToAstX (cache: IdentCache ; t: PType ; info: TLineInfo ; idgen: IdGenerator ;
45- inst= false ; allowRecursionX= false ): PNode
45+ inst= false ; allowRecursionX= false ; skipAlias = false ): PNode
4646
4747proc mapTypeToBracketX (cache: IdentCache ; name: string ; m: TMagic ; t: PType ; info: TLineInfo ;
4848 idgen: IdGenerator ;
@@ -70,7 +70,7 @@ proc objectNode(cache: IdentCache; n: PNode; idgen: IdGenerator): PNode =
7070
7171proc mapTypeToAstX (cache: IdentCache ; t: PType ; info: TLineInfo ;
7272 idgen: IdGenerator ;
73- inst= false ; allowRecursionX= false ): PNode =
73+ inst= false ; allowRecursionX= false ; skipAlias = false ): PNode =
7474 var allowRecursion = allowRecursionX
7575 template atomicType (name, m): untyped = atomicTypeX (cache, name, m, t, info, idgen)
7676 template atomicType (s): untyped = atomicTypeX (s, info)
@@ -91,7 +91,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
9191 id
9292 template newIdentDefs (s): untyped = newIdentDefs (s, s.typ)
9393
94- if inst and not allowRecursion and t.sym != nil :
94+ if inst and not allowRecursion and t.sym != nil and
95+ not (skipAlias and t.kind == tyAlias):
9596 # getTypeInst behavior: return symbol
9697 return atomicType (t.sym)
9798
@@ -124,7 +125,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
124125 if t.base != nil :
125126 result = newNodeIT (nkBracketExpr, if t.n.isNil: info else : t.n.info, t)
126127 result .add atomicType (" typeDesc" , mTypeDesc)
127- result .add mapTypeToAst ( t.base, info)
128+ result .add mapTypeToAstX (cache, t.base, info, idgen, inst, skipAlias = skipAlias )
128129 else :
129130 result = atomicType (" typeDesc" , mTypeDesc)
130131 of tyGenericInvocation:
@@ -153,7 +154,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
153154 else :
154155 result = mapTypeToAst (t.typeBodyImpl, info)
155156 of tyAlias:
156- result = mapTypeToAstX (cache, t.skipModifier, info, idgen, inst, allowRecursion)
157+ result = mapTypeToAstX (cache, t.skipModifier, info, idgen, inst, allowRecursion, skipAlias = skipAlias )
157158 of tyOrdinal:
158159 result = mapTypeToAst (t.skipModifier, info)
159160 of tyDistinct:
@@ -325,8 +326,9 @@ proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGene
325326
326327# the "Inst" version includes generic parameters in the resulting type tree
327328# and also tries to look like the corresponding Nim type declaration
328- proc opMapTypeInstToAst * (cache: IdentCache ; t: PType ; info: TLineInfo ; idgen: IdGenerator ): PNode =
329- result = mapTypeToAstX (cache, t, info, idgen, inst= true , allowRecursionX= false )
329+ proc opMapTypeInstToAst * (cache: IdentCache ; t: PType ; info: TLineInfo ; idgen: IdGenerator ; skipAlias = false ): PNode =
330+ # skipAlias: skips aliases and typedesc
331+ result = mapTypeToAstX (cache, t, info, idgen, inst= true , allowRecursionX= false , skipAlias = skipAlias)
330332
331333# the "Impl" version includes generic parameters in the resulting type tree
332334# and also tries to look like the corresponding Nim type implementation
0 commit comments