Skip to content

Commit

Permalink
fixes #22856; enables -d:nimStrictDelete (#22858)
Browse files Browse the repository at this point in the history
fixes #22856

`-d:nimStrictDelete` is introduced in 1.6.0, which promised to be
enabled in the coming versions. To keep backwards incompatibilities, it
also extends the feature of `-d:nimAuditDelete`, which now mimics the
old behaviors.
  • Loading branch information
ringabout authored Oct 24, 2023
1 parent 3095048 commit 3fd4e68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Changes affecting backward compatibility

- `-d:nimStrictDelete` becomes the default. An index error is produced when the index passed to `system.delete` was out of bounds. Use `-d:nimAuditDelete` to mimic the old behavior for backwards compatibility.

## Standard library additions and changes

Expand Down
6 changes: 1 addition & 5 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1986,10 +1986,6 @@ proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect, systemRaisesDefect, a
##
## This is an `O(n)` operation.
##
## .. note:: With `-d:nimStrictDelete`, an index error is produced when the index passed
## to it was out of bounds. `-d:nimStrictDelete` will become the default
## in upcoming versions.
##
## See also:
## * `del <#del,seq[T],Natural>`_ for O(1) operation
##
Expand All @@ -1998,7 +1994,7 @@ proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect, systemRaisesDefect, a
s.delete(2)
doAssert s == @[1, 2, 4, 5]

when defined(nimStrictDelete):
when not defined(nimAuditDelete):
if i > high(x):
# xxx this should call `raiseIndexError2(i, high(x))` after some refactoring
raise (ref IndexDefect)(msg: "index out of bounds: '" & $i & "' < '" & $x.len & "' failed")
Expand Down

0 comments on commit 3fd4e68

Please sign in to comment.