Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested inc and dec operator extensions #5348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evfinkn
Copy link

@evfinkn evfinkn commented Aug 23, 2024

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

Declaring `inc` and `dec` operator extensions as members was erroring
with "receiver must be a supertype of the return type" even though there
was no error for the same operator extensions when defined outside a
class.

^KT-24800 Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants