Skip to content

Commit 04ccd2f

Browse files
authored
revert second argument of inc not being generic (#24129)
refs #22328, fixes regression in https://forum.nim-lang.org/t/12465#76998
1 parent 680a13a commit 04ccd2f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/system/arithmetics.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
1+
proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
22
## Returns the `y`-th successor (default: 1) of the value `x`.
33
##
44
## If such a value does not exist, `OverflowDefect` is raised
@@ -7,7 +7,7 @@ proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
77
assert succ(5) == 6
88
assert succ(5, 3) == 8
99
10-
proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
10+
proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
1111
## Returns the `y`-th predecessor (default: 1) of the value `x`.
1212
##
1313
## If such a value does not exist, `OverflowDefect` is raised
@@ -16,7 +16,7 @@ proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
1616
assert pred(5) == 4
1717
assert pred(5, 3) == 2
1818
19-
proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
19+
proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
2020
## Increments the ordinal `x` by `y`.
2121
##
2222
## If such a value does not exist, `OverflowDefect` is raised or a compile
@@ -28,7 +28,7 @@ proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
2828
inc(i, 3)
2929
assert i == 6
3030
31-
proc dec*[T: Ordinal](x: var T, y: int = 1) {.magic: "Dec", noSideEffect.} =
31+
proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} =
3232
## Decrements the ordinal `x` by `y`.
3333
##
3434
## If such a value does not exist, `OverflowDefect` is raised or a compile

tests/int/tunsignedinc.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ block t4175:
3232
const j = 0u - 1u
3333
doAssert i == j
3434
doAssert j + 1u == 0u
35+
36+
block: # https://forum.nim-lang.org/t/12465#76998
37+
var a: int = 1
38+
var x: uint8 = 1
39+
a.inc(x) # Error: type mismatch
40+
doAssert a == 2

tests/varres/tprevent_forloopvar_mutations.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ discard """
22
errormsg: "type mismatch: got <int>"
33
nimout: '''tprevent_forloopvar_mutations.nim(16, 3) Error: type mismatch: got <int>
44
but expected one of:
5-
proc inc[T: Ordinal](x: var T; y: int = 1)
5+
proc inc[T, V: Ordinal](x: var T; y: V = 1)
66
first type mismatch at position: 1
77
required type for x: var T: Ordinal
88
but expression 'i' is immutable, not 'var'

0 commit comments

Comments
 (0)