Skip to content

Commit

Permalink
revert second argument of inc not being generic (#24129)
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn authored Sep 17, 2024
1 parent 680a13a commit 04ccd2f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/system/arithmetics.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
## Returns the `y`-th successor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
Expand All @@ -7,7 +7,7 @@ proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
assert succ(5) == 6
assert succ(5, 3) == 8

proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
## Returns the `y`-th predecessor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
Expand All @@ -16,7 +16,7 @@ proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
assert pred(5) == 4
assert pred(5, 3) == 2

proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
## Increments the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
Expand All @@ -28,7 +28,7 @@ proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
inc(i, 3)
assert i == 6

proc dec*[T: Ordinal](x: var T, y: int = 1) {.magic: "Dec", noSideEffect.} =
proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} =
## Decrements the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
Expand Down
6 changes: 6 additions & 0 deletions tests/int/tunsignedinc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ block t4175:
const j = 0u - 1u
doAssert i == j
doAssert j + 1u == 0u

block: # https://forum.nim-lang.org/t/12465#76998
var a: int = 1
var x: uint8 = 1
a.inc(x) # Error: type mismatch
doAssert a == 2
2 changes: 1 addition & 1 deletion tests/varres/tprevent_forloopvar_mutations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
errormsg: "type mismatch: got <int>"
nimout: '''tprevent_forloopvar_mutations.nim(16, 3) Error: type mismatch: got <int>
but expected one of:
proc inc[T: Ordinal](x: var T; y: int = 1)
proc inc[T, V: Ordinal](x: var T; y: V = 1)
first type mismatch at position: 1
required type for x: var T: Ordinal
but expression 'i' is immutable, not 'var'
Expand Down

0 comments on commit 04ccd2f

Please sign in to comment.