kotlin
kotlin copied to clipboard
Fix nested inc and dec operator extensions
This fixes KT-24800. Defining inc and dec operator extensions as members was erroring with
[INAPPLICABLE_OPERATOR_MODIFIER] 'operator' modifier is inapplicable on this function: receiver must be a supertype of the return type
At the same time, declaring inc or dec's return type to be the dispatch receiver type instead of the extension receiver type wouldn't error. For example:
object Foo
object Bar {
operator fun Foo.inc(): Foo = TODO() // error
operator fun Foo.dec(): Bar = TODO() // no error
}
// outside of Bar, defining these extensions behaves as expected
operator fun Foo.inc(): Foo = TODO() // no error
operator fun Foo.dec(): Bar = TODO() // error