summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-04-26 05:55:25 -0700
committerGitHub <noreply@github.com>2020-04-26 14:55:25 +0200
commit9384f7ad35aa36a22b31d7541254e89890d6cec2 (patch)
tree38e8a9bd5485df43e7870444b9e8fee902316634 /lib
parentd23446c6baea34438be44e7dad5a467c0a17cb27 (diff)
downloadNim-9384f7ad35aa36a22b31d7541254e89890d6cec2.tar.gz
since now takes an optional patch, eg: `since: (1, 3, 1)` (#14124)
add tests for tinclrtl
Diffstat (limited to 'lib')
-rw-r--r--lib/system.nim6
-rw-r--r--lib/system/inclrtl.nim16
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 221a538b1..3ba2050b6 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2055,7 +2055,11 @@ export dollars
 
 const
   NimMajor* {.intdefine.}: int = 1
-    ## is the major number of Nim's version.
+    ## is the major number of Nim's version. Example:
+    ##
+    ## .. code-block:: Nim
+    ##   when (NimMajor, NimMinor, NimPatch) >=  (1, 3, 1): discard
+    # See also private symbol `since: (1, 3)` reserved for stdlib
 
   NimMinor* {.intdefine.}: int = 3
     ## is the minor number of Nim's version.
diff --git a/lib/system/inclrtl.nim b/lib/system/inclrtl.nim
index e84794c74..37cdb74d8 100644
--- a/lib/system/inclrtl.nim
+++ b/lib/system/inclrtl.nim
@@ -49,8 +49,20 @@ when defined(nimlocks):
 else:
   {.pragma: benign, gcsafe.}
 
+template isSince(version: (int, int)): bool =
+  (NimMajor, NimMinor) >= version
+template isSince(version: (int, int, int)): bool =
+  (NimMajor, NimMinor, NimPatch) >= version
+
 template since(version, body: untyped) {.dirty, used.} =
-  ## limitation: can't be used to annotate a template (eg typetraits.get), would
+  ## Usage:
+  ##
+  ## .. code-block:: Nim
+  ##   proc fun*() {since: (1, 3).}
+  ##   proc fun*() {since: (1, 3, 1).}
+  ##
+  ## Limitation: can't be used to annotate a template (eg typetraits.get), would
   ## error: cannot attach a custom pragma.
-  when (NimMajor, NimMinor) >= version:
+  # `dirty` needed because `NimMajor` may not yet be defined in caller.
+  when isSince(version):
     body