@@ -42,7 +42,7 @@ proc atomicTypeX(s: PSym; info: TLineInfo): PNode =
42
42
result .info = info
43
43
44
44
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGenerator;
45
- inst= false ; allowRecursionX= false ): PNode
45
+ inst= false ; allowRecursionX= false ; skipAlias = false ): PNode
46
46
47
47
proc mapTypeToBracketX(cache: IdentCache; name: string ; m: TMagic; t: PType; info: TLineInfo;
48
48
idgen: IdGenerator;
@@ -70,7 +70,7 @@ proc objectNode(cache: IdentCache; n: PNode; idgen: IdGenerator): PNode =
70
70
71
71
proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
72
72
idgen: IdGenerator;
73
- inst= false ; allowRecursionX= false ): PNode =
73
+ inst= false ; allowRecursionX= false ; skipAlias = false ): PNode =
74
74
var allowRecursion = allowRecursionX
75
75
template atomicType(name, m): untyped = atomicTypeX(cache, name, m, t, info, idgen)
76
76
template atomicType(s): untyped = atomicTypeX(s, info)
@@ -91,7 +91,8 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
91
91
id
92
92
template newIdentDefs(s): untyped = newIdentDefs(s, s.typ)
93
93
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):
95
96
# getTypeInst behavior: return symbol
96
97
return atomicType(t.sym)
97
98
@@ -124,7 +125,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
124
125
if t.base != nil :
125
126
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else : t.n.info, t)
126
127
result .add atomicType(" typeDesc" , mTypeDesc)
127
- result .add mapTypeToAst( t.base, info)
128
+ result .add mapTypeToAstX(cache, t.base, info, idgen, inst, skipAlias = skipAlias )
128
129
else :
129
130
result = atomicType(" typeDesc" , mTypeDesc)
130
131
of tyGenericInvocation:
@@ -153,7 +154,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
153
154
else :
154
155
result = mapTypeToAst(t.typeBodyImpl, info)
155
156
of tyAlias:
156
- result = mapTypeToAstX(cache, t.skipModifier, info, idgen, inst, allowRecursion)
157
+ result = mapTypeToAstX(cache, t.skipModifier, info, idgen, inst, allowRecursion, skipAlias = skipAlias )
157
158
of tyOrdinal:
158
159
result = mapTypeToAst(t.skipModifier, info)
159
160
of tyDistinct:
@@ -325,8 +326,9 @@ proc opMapTypeToAst*(cache: IdentCache; t: PType; info: TLineInfo; idgen: IdGene
325
326
326
327
# the "Inst" version includes generic parameters in the resulting type tree
327
328
# 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)
330
332
331
333
# the "Impl" version includes generic parameters in the resulting type tree
332
334
# and also tries to look like the corresponding Nim type implementation
0 commit comments