diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semmagic.nim | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 307e21ec6..990538096 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -172,6 +172,22 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym) let complexObj = containsGarbageCollectedRef(t) or hasDestructor(t) result = newIntNodeT(toInt128(ord(not complexObj)), traitCall, c.graph) + of "isNamedTuple": + let cond = operand.kind == tyTuple and operand.n != nil + result = newIntNodeT(toInt128(ord(cond)), traitCall, c.graph) + of "distinctBase": + var arg = operand.skipTypes({tyGenericInst}) + if arg.kind == tyDistinct: + while arg.kind == tyDistinct: + arg = arg.base + arg = arg.skipTypes(skippedTypes + {tyGenericInst}) + var resType = newType(tyTypeDesc, operand.owner) + rawAddSon(resType, arg) + result = toNode(resType, traitCall.info) + else: + localError(c.config, traitCall.info, + "distinctBase expects a distinct type as argument. The given type was " & typeToString(operand)) + result = newType(tyError, context).toNode(traitCall.info) else: localError(c.config, traitCall.info, "unknown trait: " & s) result = newNodeI(nkEmpty, traitCall.info) |