summary refs log tree commit diff stats
path: root/compiler/semmagic.nim
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2020-01-07 23:36:57 +0000
committerAndreas Rumpf <rumpf_a@web.de>2020-01-08 00:36:57 +0100
commit871d5e79b1dc54c1657a1d7f85788e8bd8f4fb28 (patch)
tree41353387591564db35c1deb7a9619fcf3a3b80d5 /compiler/semmagic.nim
parent8bcc7e8b9ea39524bac14f6c89de5213509f4099 (diff)
downloadNim-871d5e79b1dc54c1657a1d7f85788e8bd8f4fb28.tar.gz
distinctBase type trait for distinct types (#13031)
Diffstat (limited to 'compiler/semmagic.nim')
-rw-r--r--compiler/semmagic.nim16
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)