diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 564ab7ac3c..0dd67b1842 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1295,7 +1295,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = localError(n.info, errGenerated, "cannot bind another '" & s.name.s & "' to: " & typeToString(obj)) noError = true - if not noError: + if not noError and sfSystemModule notin s.owner.flags: localError(n.info, errGenerated, "signature for '" & s.name.s & "' must be proc[T: object](x: var T)") else: @@ -1351,8 +1351,9 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = localError(n.info, errGenerated, "cannot bind another '" & s.name.s & "' to: " & typeToString(obj)) return - localError(n.info, errGenerated, - "signature for '" & s.name.s & "' must be proc[T: object](x: var T; y: T)") + if sfSystemModule notin s.owner.flags: + localError(n.info, errGenerated, + "signature for '" & s.name.s & "' must be proc[T: object](x: var T; y: T)") else: if sfOverriden in s.flags: localError(n.info, errGenerated, diff --git a/lib/system.nim b/lib/system.nim index ddc72ffaf4..10560edaa3 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -285,6 +285,13 @@ proc low*(x: string): int {.magic: "Low", noSideEffect.} ## low(2) #=> -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): # :array|openarray|string|seq|cstring|tuple proc `[]`*[I: Ordinal;T](a: T; i: I): T {. @@ -293,10 +300,10 @@ when defined(nimArrIdx): x: S) {.noSideEffect, magic: "ArrPut".} proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".} when defined(nimNewRuntime): - template `=destroy`*[T](x: var T) = + proc `=destroy`*[T](x: var T) {.inline.} = ## generic `destructor`:idx: implementation that can be overriden. 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. shallowCopy(x, y) @@ -1488,13 +1495,6 @@ proc add *[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} = setLen(x, xl + y.len) 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.} = ## deletes the item at index `i` by putting ``x[high(x)]`` into position `i`. ## This is an O(1) operation.