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

unwrapCompanionClass fails to unwrap private companions when on kotlin 1.4+ #182

Closed
ilya-yamschikov opened this issue Jul 3, 2021 · 0 comments

Comments

@ilya-yamschikov
Copy link
Contributor

I have a class with a companion object that extends KLogging(). I expect that the logger name would contain just the enclosing class name without the companion object class name. Even when a companion object is private.
This works fine when compiling it with kotlin 1.3 and below. This doesn't work with 1.4+.

Consider an example:

class PublicCompanion {
    public companion object : KLogging()
    val loggerName = logger.name
}

class PrivateCompanion {
    private companion object : KLogging()
    val loggerName = logger.name
}

fun main() {
    println(PublicCompanion().loggerName)
    println(PrivateCompanion().loggerName)
}

When compiling with kotlin 1.3 it outputs:

PublicCompanion
PrivateCompanion

While with 1.4 it changes to:

PublicCompanion
PrivateCompanion$Companion

There was a change in what visibility modifiers are put into bytecode by the kotlin compiler:
https://kotlinlang.org/docs/compatibility-guide-14.html#the-instance-field-of-a-companion-object-more-visible-than-the-companion-object-class-itself
As a reslut a reflection method that is used by unwrapCompanionClass started failing on private companions.
So that it doesn't unwrap companion class name when it's private any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant