This message was deleted.
# language-proposals
s
This message was deleted.
c
This works when overriding `plusAssign`:
Copy code
private interface Slot {
    operator fun plusAssign(count: Int): Unit
    operator fun minus(count: Int): Slot
}

private interface Shelf {
    operator fun get(row: Int, col: Int): Slot
    operator fun set(row: Int, col: Int, items: Slot)
}

private fun foo() {
    val shelf = object: Shelf {
        override fun get(row: Int, col: Int): Slot {
            TODO()
        }

        override fun set(row: Int, col: Int, items: Slot) {
            TODO()
        }
    }

    val slot = shelf[1, 2]
    shelf[1, 2] += 2
    shelf[1, 2] = slot - 1
}
a
This is not the same semantic. += means adding something to the existing value. Set means replacing the current value. += implies a merge of values and set does not do this at all.
For me, += means that the left value is updated, not replaced. Therefore, using get, plus and set is not equivalent to plusAssign in term of memory/object management. If inplace update is a strong criterion of the operator (personnally, I think it should, but that is a personal opinion), then the compiler should never allow += to be replaced by get, plus and set. Otherwise (in-place update not enforced), then yes, your propsal is valid.