Add optional recursive arg to distinctBase (v2) (#18659)
* Add optional recursive arg to distinctBase * Add docs and examples Co-authored-by: ALANVF <alan.invents@gmail.com>
This commit is contained in:
parent
988c02b7cb
commit
8ce782d463
4 changed files with 18 additions and 10 deletions
|
|
@ -190,9 +190,10 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym)
|
|||
result = newIntNodeT(toInt128(operand.len), traitCall, c.idgen, c.graph)
|
||||
of "distinctBase":
|
||||
var arg = operand.skipTypes({tyGenericInst})
|
||||
let rec = semConstExpr(c, traitCall[2]).intVal != 0
|
||||
while arg.kind == tyDistinct:
|
||||
arg = arg.base
|
||||
arg = arg.skipTypes(skippedTypes + {tyGenericInst})
|
||||
arg = arg.base.skipTypes(skippedTypes + {tyGenericInst})
|
||||
if not rec: break
|
||||
result = getTypeDescNode(c, arg, operand.owner, traitCall.info)
|
||||
else:
|
||||
localError(c.config, traitCall.info, "unknown trait: " & s)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue