fixes #8603
This commit is contained in:
parent
df68c2da49
commit
f6def4286c
2 changed files with 37 additions and 28 deletions
|
|
@ -322,7 +322,14 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
n.sons[i] = semGenericStmtScope(c, n.sons[i], flags, ctx)
|
n.sons[i] = semGenericStmtScope(c, n.sons[i], flags, ctx)
|
||||||
of nkWhenStmt:
|
of nkWhenStmt:
|
||||||
for i in countup(0, sonsLen(n)-1):
|
for i in countup(0, sonsLen(n)-1):
|
||||||
n.sons[i] = semGenericStmt(c, n.sons[i], flags+{withinMixin}, ctx)
|
# bug #8603: conditions of 'when' statements are not
|
||||||
|
# in a 'mixin' context:
|
||||||
|
let it = n[i]
|
||||||
|
if it.kind in {nkElifExpr, nkElifBranch}:
|
||||||
|
n.sons[i].sons[0] = semGenericStmt(c, it[0], flags, ctx)
|
||||||
|
n.sons[i].sons[1] = semGenericStmt(c, it[1], flags+{withinMixin}, ctx)
|
||||||
|
else:
|
||||||
|
n.sons[i] = semGenericStmt(c, it, flags+{withinMixin}, ctx)
|
||||||
of nkWhileStmt:
|
of nkWhileStmt:
|
||||||
openScope(c)
|
openScope(c)
|
||||||
for i in countup(0, sonsLen(n)-1):
|
for i in countup(0, sonsLen(n)-1):
|
||||||
|
|
|
||||||
|
|
@ -203,23 +203,6 @@ proc `or`*(x, y: bool): bool {.magic: "Or", noSideEffect.}
|
||||||
proc `xor`*(x, y: bool): bool {.magic: "Xor", noSideEffect.}
|
proc `xor`*(x, y: bool): bool {.magic: "Xor", noSideEffect.}
|
||||||
## Boolean `exclusive or`; returns true iff ``x != y``.
|
## Boolean `exclusive or`; returns true iff ``x != y``.
|
||||||
|
|
||||||
proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
|
||||||
## creates a new object of type ``T`` and returns a safe (traced)
|
|
||||||
## reference to it in ``a``.
|
|
||||||
|
|
||||||
proc new*(T: typedesc): auto =
|
|
||||||
## creates a new object of type ``T`` and returns a safe (traced)
|
|
||||||
## reference to it as result value.
|
|
||||||
##
|
|
||||||
## When ``T`` is a ref type then the resulting type will be ``T``,
|
|
||||||
## otherwise it will be ``ref T``.
|
|
||||||
when (T is ref):
|
|
||||||
var r: T
|
|
||||||
else:
|
|
||||||
var r: ref T
|
|
||||||
new(r)
|
|
||||||
return r
|
|
||||||
|
|
||||||
const ThisIsSystem = true
|
const ThisIsSystem = true
|
||||||
|
|
||||||
proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||||
|
|
@ -1331,6 +1314,23 @@ proc `is`*[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
||||||
template `isnot`*(x, y: untyped): untyped = not (x is y)
|
template `isnot`*(x, y: untyped): untyped = not (x is y)
|
||||||
## Negated version of `is`. Equivalent to ``not(x is y)``.
|
## Negated version of `is`. Equivalent to ``not(x is y)``.
|
||||||
|
|
||||||
|
proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||||
|
## creates a new object of type ``T`` and returns a safe (traced)
|
||||||
|
## reference to it in ``a``.
|
||||||
|
|
||||||
|
proc new*(T: typedesc): auto =
|
||||||
|
## creates a new object of type ``T`` and returns a safe (traced)
|
||||||
|
## reference to it as result value.
|
||||||
|
##
|
||||||
|
## When ``T`` is a ref type then the resulting type will be ``T``,
|
||||||
|
## otherwise it will be ``ref T``.
|
||||||
|
when (T is ref):
|
||||||
|
var r: T
|
||||||
|
else:
|
||||||
|
var r: ref T
|
||||||
|
new(r)
|
||||||
|
return r
|
||||||
|
|
||||||
proc `of`*[T, S](x: typeDesc[T], y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: typeDesc[T], y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
||||||
proc `of`*[T, S](x: T, y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: T, y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
||||||
proc `of`*[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
||||||
|
|
@ -2090,6 +2090,8 @@ when not defined(nimscript) and hasAlloc:
|
||||||
## returns the number of bytes on the shared heap that are owned by the
|
## returns the number of bytes on the shared heap that are owned by the
|
||||||
## process. This is only available when threads are enabled.
|
## process. This is only available when threads are enabled.
|
||||||
|
|
||||||
|
proc `|`*(a, b: typedesc): typedesc = discard
|
||||||
|
|
||||||
when sizeof(int) <= 2:
|
when sizeof(int) <= 2:
|
||||||
type IntLikeForCount = int|int8|int16|char|bool|uint8|enum
|
type IntLikeForCount = int|int8|int16|char|bool|uint8|enum
|
||||||
else:
|
else:
|
||||||
|
|
@ -2640,6 +2642,16 @@ proc `<`*[T: tuple](x, y: T): bool =
|
||||||
if c > 0: return false
|
if c > 0: return false
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
|
||||||
|
## Special compile-time procedure that checks whether `x` can be compiled
|
||||||
|
## without any semantic error.
|
||||||
|
## This can be used to check whether a type supports some operation:
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## when compiles(3 + 4):
|
||||||
|
## echo "'+' for integers is available"
|
||||||
|
discard
|
||||||
|
|
||||||
proc `$`*[T: tuple|object](x: T): string =
|
proc `$`*[T: tuple|object](x: T): string =
|
||||||
## generic ``$`` operator for tuples that is lifted from the components
|
## generic ``$`` operator for tuples that is lifted from the components
|
||||||
## of `x`. Example:
|
## of `x`. Example:
|
||||||
|
|
@ -4051,16 +4063,6 @@ when hasAlloc:
|
||||||
x[j+i] = item[j]
|
x[j+i] = item[j]
|
||||||
inc(j)
|
inc(j)
|
||||||
|
|
||||||
proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
|
|
||||||
## Special compile-time procedure that checks whether `x` can be compiled
|
|
||||||
## without any semantic error.
|
|
||||||
## This can be used to check whether a type supports some operation:
|
|
||||||
##
|
|
||||||
## .. code-block:: Nim
|
|
||||||
## when compiles(3 + 4):
|
|
||||||
## echo "'+' for integers is available"
|
|
||||||
discard
|
|
||||||
|
|
||||||
when declared(initDebugger):
|
when declared(initDebugger):
|
||||||
initDebugger()
|
initDebugger()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue