mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 11:54:11 +00:00
since now takes an optional patch, eg: since: (1, 3, 1) (#14124)
add tests for tinclrtl
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
32
tests/stdlib/tinclrtl.nim
Normal file
32
tests/stdlib/tinclrtl.nim
Normal file
@@ -0,0 +1,32 @@
|
||||
include system/inclrtl
|
||||
|
||||
proc fun1(): int {.since: (1,3).} = 12
|
||||
proc fun1Bad(): int {.since: (99,3).} = 12
|
||||
proc fun2(): int {.since: (1,3,1).} = 12
|
||||
proc fun2Bad(): int {.since: (99,3,1).} = 12
|
||||
|
||||
doAssert fun1() == 12
|
||||
doAssert declared(fun1)
|
||||
doAssert not declared(fun1Bad)
|
||||
|
||||
doAssert fun2() == 12
|
||||
doAssert declared(fun2)
|
||||
doAssert not declared(fun2Bad)
|
||||
|
||||
var ok = false
|
||||
since (1, 3):
|
||||
ok = true
|
||||
doAssert ok
|
||||
|
||||
ok = false
|
||||
since (1, 3, 1):
|
||||
ok = true
|
||||
doAssert ok
|
||||
|
||||
since (99,3):
|
||||
doAssert false
|
||||
|
||||
when false:
|
||||
# pending https://github.com/timotheecour/Nim/issues/129
|
||||
# Error: cannot attach a custom pragma to 'fun3'
|
||||
template fun3(): int {.since: (1, 3).} = 12
|
||||
Reference in New Issue
Block a user