KSValueArgument#name with @JvmName is inconsistent between source and classpath
- Dominant language
- Kotlin
- Stars
- 3.5k
- Forks
- 415
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 53
Description
Consider a project with two libraries, `:main -> :lib` and the following sources:
```kotlin
annotation class MyAnnotation(@get:JvmName("newA") val a: String)
// :main
@MyAnnotation(a = "a")
class MainKotlin
@MyAnnotation(newA = "a")
class MainJava {}
// :lib
@MyAnnotation(a = "a")
class LibKotlin
@MyAnnotation(newA = "a")
class LibJava {}
```
With the following KSP processor:
```kotlin
override fun process(resolver: Resolver): List {
fun printAnnotationInfo(name: String) {
val declaration = resolver.getClassDeclarationByName(resolver.getKSNameFromString(name))!!
val annotation = declaration.annotations.single { it.shortName.asString() == "MyAnnotation" }
println("$name: ${annotation.arguments.map { it.name?.asString() }}")
}
printAnnotationInfo("MainKotlin")
printAnnotationInfo("MainJava")
printAnnotationInfo("LibKotlin")
printAnnotationInfo("LibJava")
return listOf()
}
```
When processing `:main`, this results in the following output:
```
MainKotlin: [a]
MainJava: [newA]
LibKotlin: [newA]
LibJava: [newA]
```
Note that `MainKotlin` gives the source name but all other cases give the jvm name.
I think at the very least, `LibKotlin` and `MainKotlin` should return the same result. IMO, they should return the name used in source, i.e. `a` and there should be a `Resolver#getJvmName(KSValueArgument)` (similar to what exists for [properties and functions](https://github.com/google/ksp/blob/main/api/src/main/kotlin/com/google/devtools/ksp/processing/Resolver.kt#L137-L184)) to get the JVM version of the name.
As for `MainJava` and `LibJava`, I can see why `newA` is used since that's the name at the usage site. However, personally, I'd rather the behavior to match the Kotlin source behavior described above for consistency.
Contributor guide
Research direction
Start by reproducing the processor output for MainKotlin, MainJava, LibKotlin, and LibJava, then inspect Resolver#getJvmName for properties and functions in Resolver.kt as the related API reference. Done means the source and classpath cases have a consistent, documented value-argument name behavior, with a clear decision on JVM-name access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100