summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-02-01 04:10:52 -0800
committerGitHub <noreply@github.com>2021-02-01 13:10:52 +0100
commit1a745768540c0a27d66701d0eca98e968f1d9297 (patch)
tree894da444130123f5e96751e953c885297a6fb132 /lib
parent25c75752d07fccc00682890875f3ce6c13f61d90 (diff)
downloadNim-1a745768540c0a27d66701d0eca98e968f1d9297.tar.gz
distinctBase now is identity instead of error for non distinct types (#16891)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/typetraits.nim14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim
index 45e2a86c2..859a06cac 100644
--- a/lib/pure/typetraits.nim
+++ b/lib/pure/typetraits.nim
@@ -86,26 +86,26 @@ proc isNamedTuple*(T: typedesc): bool {.magic: "TypeTrait".} =
     doAssert isNamedTuple(tuple[name: string, age: int])
 
 proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".} =
-  ## Returns the base type for distinct types. This works only
-  ## for distinct types and produces a compile time error otherwise.
+  ## Returns the base type for distinct types, or the type itself otherwise.
   ##
   ## **See also:**
   ## * `distinctBase template <#distinctBase.t,T>`_
   runnableExamples:
     type MyInt = distinct int
-
     doAssert distinctBase(MyInt) is int
-    doAssert not compiles(distinctBase(int))
+    doAssert distinctBase(int) is int
 
 since (1, 1):
   template distinctBase*[T](a: T): untyped =
     ## Overload of `distinctBase <#distinctBase,typedesc>`_ for values.
     runnableExamples:
       type MyInt = distinct int
-
       doAssert 12.MyInt.distinctBase == 12
-
-    distinctBase(type(a))(a)
+      doAssert 12.distinctBase == 12
+    when T is distinct:
+      distinctBase(type(a))(a)
+    else: # avoids hint ConvFromXtoItselfNotNeeded
+      a
 
   proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait".} =
     ## Returns the number of elements of the tuple type `T`.