diff options
author | Clyybber <darkmine956@gmail.com> | 2020-08-27 15:50:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 15:50:59 +0200 |
commit | fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82 (patch) | |
tree | c6e573d9ac221c786ac9e0ca2cf0f186d87a6bbe /lib/system.nim | |
parent | d11933ad998fb0a3eb51bbefbaa53e583aaa3ac1 (diff) | |
download | Nim-fb58066b61b14f4a1d6cdb0f4a8f0a9ea4174d82.tar.gz |
Fix #5691 (#15158)
* Fix #5691 * Cleanup and thoughts * Use scope approach * Seperate defined/declared/declaredInScope magics * Fix declaredInScope * Update spec accordingly
Diffstat (limited to 'lib/system.nim')
-rw-r--r-- | lib/system.nim | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/system.nim b/lib/system.nim index 93386c4ae..204a1194e 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -150,25 +150,30 @@ else: template runnableExamples*(doccmd = "", body: untyped) = discard -proc declared*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.} - ## Special compile-time procedure that checks whether `x` is - ## declared. `x` has to be an identifier or a qualified identifier. - ## - ## See also: - ## * `declaredInScope <#declaredInScope,untyped>`_ - ## - ## This can be used to check whether a library provides a certain - ## feature or not: - ## - ## .. code-block:: Nim - ## when not declared(strutils.toUpper): - ## # provide our own toUpper proc here, because strutils is - ## # missing it. +when defined(nimHasDeclaredMagic): + proc declared*(x: untyped): bool {.magic: "Declared", noSideEffect, compileTime.} + ## Special compile-time procedure that checks whether `x` is + ## declared. `x` has to be an identifier or a qualified identifier. + ## + ## See also: + ## * `declaredInScope <#declaredInScope,untyped>`_ + ## + ## This can be used to check whether a library provides a certain + ## feature or not: + ## + ## .. code-block:: Nim + ## when not declared(strutils.toUpper): + ## # provide our own toUpper proc here, because strutils is + ## # missing it. +else: + proc declared*(x: untyped): bool {.magic: "Defined", noSideEffect, compileTime.} -proc declaredInScope*(x: untyped): bool {. - magic: "DefinedInScope", noSideEffect, compileTime.} - ## Special compile-time procedure that checks whether `x` is - ## declared in the current scope. `x` has to be an identifier. +when defined(nimHasDeclaredMagic): + proc declaredInScope*(x: untyped): bool {.magic: "DeclaredInScope", noSideEffect, compileTime.} + ## Special compile-time procedure that checks whether `x` is + ## declared in the current scope. `x` has to be an identifier. +else: + proc declaredInScope*(x: untyped): bool {.magic: "DefinedInScope", noSideEffect, compileTime.} proc `addr`*[T](x: var T): ptr T {.magic: "Addr", noSideEffect.} = ## Builtin `addr` operator for taking the address of a memory location. |