default '=sink' and '=destroy' cannot be templates
This commit is contained in:
parent
0be71677d9
commit
9df766491d
2 changed files with 13 additions and 12 deletions
|
|
@ -1295,7 +1295,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
localError(n.info, errGenerated,
|
localError(n.info, errGenerated,
|
||||||
"cannot bind another '" & s.name.s & "' to: " & typeToString(obj))
|
"cannot bind another '" & s.name.s & "' to: " & typeToString(obj))
|
||||||
noError = true
|
noError = true
|
||||||
if not noError:
|
if not noError and sfSystemModule notin s.owner.flags:
|
||||||
localError(n.info, errGenerated,
|
localError(n.info, errGenerated,
|
||||||
"signature for '" & s.name.s & "' must be proc[T: object](x: var T)")
|
"signature for '" & s.name.s & "' must be proc[T: object](x: var T)")
|
||||||
else:
|
else:
|
||||||
|
|
@ -1351,6 +1351,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
localError(n.info, errGenerated,
|
localError(n.info, errGenerated,
|
||||||
"cannot bind another '" & s.name.s & "' to: " & typeToString(obj))
|
"cannot bind another '" & s.name.s & "' to: " & typeToString(obj))
|
||||||
return
|
return
|
||||||
|
if sfSystemModule notin s.owner.flags:
|
||||||
localError(n.info, errGenerated,
|
localError(n.info, errGenerated,
|
||||||
"signature for '" & s.name.s & "' must be proc[T: object](x: var T; y: T)")
|
"signature for '" & s.name.s & "' must be proc[T: object](x: var T; y: T)")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,13 @@ proc low*(x: string): int {.magic: "Low", noSideEffect.}
|
||||||
## low(2) #=> -9223372036854775808
|
## low(2) #=> -9223372036854775808
|
||||||
## low(int) #=> -9223372036854775808
|
## low(int) #=> -9223372036854775808
|
||||||
|
|
||||||
|
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
||||||
|
## use this instead of `=` for a `shallow copy`:idx:. The shallow copy
|
||||||
|
## only changes the semantics for sequences and strings (and types which
|
||||||
|
## contain those). Be careful with the changed semantics though! There
|
||||||
|
## is a reason why the default assignment does a deep copy of sequences
|
||||||
|
## and strings.
|
||||||
|
|
||||||
when defined(nimArrIdx):
|
when defined(nimArrIdx):
|
||||||
# :array|openarray|string|seq|cstring|tuple
|
# :array|openarray|string|seq|cstring|tuple
|
||||||
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
||||||
|
|
@ -293,10 +300,10 @@ when defined(nimArrIdx):
|
||||||
x: S) {.noSideEffect, magic: "ArrPut".}
|
x: S) {.noSideEffect, magic: "ArrPut".}
|
||||||
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
||||||
when defined(nimNewRuntime):
|
when defined(nimNewRuntime):
|
||||||
template `=destroy`*[T](x: var T) =
|
proc `=destroy`*[T](x: var T) {.inline.} =
|
||||||
## generic `destructor`:idx: implementation that can be overriden.
|
## generic `destructor`:idx: implementation that can be overriden.
|
||||||
discard
|
discard
|
||||||
template `=sink`*[T](x: var T; y: T) =
|
proc `=sink`*[T](x: var T; y: T) {.inline.} =
|
||||||
## generic `sink`:idx: implementation that can be overriden.
|
## generic `sink`:idx: implementation that can be overriden.
|
||||||
shallowCopy(x, y)
|
shallowCopy(x, y)
|
||||||
|
|
||||||
|
|
@ -1488,13 +1495,6 @@ proc add *[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
|
||||||
setLen(x, xl + y.len)
|
setLen(x, xl + y.len)
|
||||||
for i in 0..high(y): x[xl+i] = y[i]
|
for i in 0..high(y): x[xl+i] = y[i]
|
||||||
|
|
||||||
proc shallowCopy*[T](x: var T, y: T) {.noSideEffect, magic: "ShallowCopy".}
|
|
||||||
## use this instead of `=` for a `shallow copy`:idx:. The shallow copy
|
|
||||||
## only changes the semantics for sequences and strings (and types which
|
|
||||||
## contain those). Be careful with the changed semantics though! There
|
|
||||||
## is a reason why the default assignment does a deep copy of sequences
|
|
||||||
## and strings.
|
|
||||||
|
|
||||||
proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
proc del*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
|
## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`.
|
||||||
## This is an O(1) operation.
|
## This is an O(1) operation.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue