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

[KSP2] JVM names for property getters/setters are incorrect if they start with "is" #2181

Closed
jonamireh opened this issue Oct 30, 2024 · 0 comments · Fixed by #2185
Closed
Milestone

Comments

@jonamireh
Copy link
Contributor

jonamireh commented Oct 30, 2024

Summary

JVM names for Kotlin property getters & setters are incorrect when the Kotlin property name starts with "is". Specifically, Resolver.getJvmName is returning a name that does not match what the Kotlin compiler generated.

Environment

KSP: 2.1.0-Beta2-1.0.26 with KSP2
Kotlin: 2.1.0-Beta2
AGP: 8.7.1
Gradle: 8.10

Context

Consider the following code:

package dev.jonamireh

interface TestInterface {
    var isOpen: String
}
  • For the property getter of isOpen, Resolver.getJvmName() is returning getIsOpen even though the Kotlin compiler generated isOpen.
  • For the property setter of isOpen, Resolver.getJvmName() is returning setIsOpen even though the Kotlin compiler generated setOpen.

This permuation is documented in the Kotlin documentation for Calling Kotlin from Java:

If the name of the property starts with is, a different name mapping rule is used: the name of the getter will be the same as the property name, and the name of the setter will be obtained by replacing is with set. For example, for a property isOpen, the getter will be called isOpen() and the setter will be called setOpen(). This rule applies for properties of any type, not just Boolean.

Sample project

Here's a sample project where :processor will print the JVM name according to getJvmName for each property getter & setter. You can test out what KSP thinks the getter/setter should be with:

./gradlew :jvm:assemble --info --rerun-tasks | grep "\[ksp\]"
@jonamireh jonamireh changed the title [KSP2] JVM names for property getters/setters are incorrect when they start with "is" [KSP2] JVM names for property getters/setters are incorrect if they start with "is" Oct 30, 2024
@ting-yuan ting-yuan added this to the 1.0.27 milestone Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants