# foo.nim
type
Foo* = object
bar: int
proc `bar`*(f: var Foo): int {.inline.} =
f.bar
proc `bar=`*(f: var Foo, val: int) {.inline.} =
f.bar = val
Run
# main.nim
import foo
var f: Foo
f.bar += 1
echo f.bar
Run
Results in:
Error: type mismatch: got <int, int literal(1)>
but expected one of:
proc `+=`[T: SomeOrdinal | uint | uint64](x: var T; y: T)
for a 'var' type a variable needs to be passed, but 'bar(f)' is immutable
proc `+=`[T: float | float32 | float64](x: var T; y: T)
first type mismatch at position: 1
required type: var T: float or float32 or float64
but expression 'bar(f)' is of type: int
for a 'var' type a variable needs to be passed, but 'bar(f)' is immutable
expression: bar(f) += 1
Run