summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-02-07 04:27:28 -0800
committerGitHub <noreply@github.com>2020-02-07 13:27:28 +0100
commitc0a2e2ed92610933983d1edb57d1ad0204189f61 (patch)
treec9d03980c9a64d9c6dfaedb16e033731af7df7ec /lib
parentabd660c407d00d0c4f2129ff11bfc69badda8ece (diff)
downloadNim-c0a2e2ed92610933983d1edb57d1ad0204189f61.tar.gz
replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple in dollars.nim (#13347)
* replace old problematic isNamedTuple implementation by TypeTrait isNamedTuple

* fix for bootstrap
Diffstat (limited to 'lib')
-rw-r--r--lib/system/dollars.nim26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/system/dollars.nim b/lib/system/dollars.nim
index 64860ef39..664f1c30d 100644
--- a/lib/system/dollars.nim
+++ b/lib/system/dollars.nim
@@ -49,18 +49,22 @@ proc `$`*(t: typedesc): string {.magic: "TypeTrait".}
   ##   doAssert $(type("Foo")) == "string"
   ##   static: doAssert $(type(@['A', 'B'])) == "seq[char]"
 
+when defined(nimHasIsNamedTuple):
+  proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
+else:
+  # for bootstrap; remove after release 1.2
+  proc isNamedTuple(T: typedesc): bool =
+    # Taken from typetraits.
+    when T isnot tuple: result = false
+    else:
+      var t: T
+      for name, _ in t.fieldPairs:
+        when name == "Field0":
+          return compiles(t.Field0)
+        else:
+          return true
+      return false
 
-proc isNamedTuple(T: typedesc): bool =
-  # Taken from typetraits.
-  when T isnot tuple: result = false
-  else:
-    var t: T
-    for name, _ in t.fieldPairs:
-      when name == "Field0":
-        return compiles(t.Field0)
-      else:
-        return true
-    return false
 
 proc `$`*[T: tuple|object](x: T): string =
   ## Generic ``$`` operator for tuples that is lifted from the components