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] Mangled names for internal functions are incorrect for Android modules #2180

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

[KSP2] Mangled names for internal functions are incorrect for Android modules #2180

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

Comments

@jonamireh
Copy link
Contributor

jonamireh commented Oct 30, 2024

Summary

Mangled names for internal functions are incorrect when the class is present in an Android application or library module. Specifically, Resolver.getJvmName is returning a name that does not match what the Kotlin compiler generated.

Looks like there's already a downstream issue in Dagger: google/dagger#4493

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 for an Android Library module :library:

package dev.jonamireh

class TestClass {
    internal fun mangled() {
    }
}

The actual generated JVM method name for mangled is mangled$library even though the Kotlin compiler generated mangled$library_debug

JVM Modules

For the same code in a Kotlin JVM module named :jvm will be correct, with both the Kotlin compiler and KSP generating mangled$jvm.

Potential Cause

As a part of #1847, an API was added to retrieve the module name for mangled internal members. This PR also changed how the module name is fed to KSP to match what's expected for JVM modules. However, I think the previous version worked for Android modules. Obviously, KSP needs to handle each module type differently

Sample project

Here's a sample project where :processor will print the JVM name according to getJvmName for each internal function. You can test out what KSP thinks the mangled should be with:

./gradlew :library:assembleDebug --info --rerun-tasks | grep "\[ksp\]"

You can swap out :library for :app or :jvm to see the result in Android application and Kotlin JVM modules, respectively as well

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

Successfully merging a pull request may close this issue.

2 participants