Skip to content

fix: sanitize ':' in internal-name module suffix so KSP 2.3.9 works with Kotlin 2.4.0 default module names#2981

Open
mvanhorn wants to merge 2 commits into
google:mainfrom
mvanhorn:fix/2964-mangled-name-colon-sanitize
Open

fix: sanitize ':' in internal-name module suffix so KSP 2.3.9 works with Kotlin 2.4.0 default module names#2981
mvanhorn wants to merge 2 commits into
google:mainfrom
mvanhorn:fix/2964-mangled-name-colon-sanitize

Conversation

@mvanhorn

Copy link
Copy Markdown

Summary

KSP's internal-member name mangling now sanitizes the module-name suffix the same way the Kotlin compiler does, instead of replacing only . and -. Kotlin 2.4.0's consistent ${project.group}:${project.name} default module names inject a literal : into the mangled JVM name, and downstream processors that build generated class names from KSP's reported JVM name fail with Can't escape identifier ... because it contains illegal characters: : (the Dagger/Hilt report in #2964).

Why this matters

KSP's reported JVM names need to agree byte-for-byte with what kotlinc actually emits. The compiler already solved the analogous problem for .kotlin_module files (KT-69701) with NameUtils.sanitizeAsJavaIdentifier; toSuffix in kotlin-analysis-api/.../util.kt now applies the same sanitization, covering both the KaSourceModule and KaLibraryModule branches. The workarounds in the issue thread (drop internal, override moduleName) stop being necessary.

Testing

mangledNames.kt test data now covers a module name carrying : and other non-identifier characters. The colon-bearing compiler module name is passed through a test-harness hook (AbstractKSPAATest) rather than the test module directory name, so the Windows CI leg, where : is illegal in path components, is unaffected.

Fixes #2964

@jaschdoc

Copy link
Copy Markdown
Collaborator

Hi thank you for the PR! I will take a look and get back to you :)

@jaschdoc jaschdoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting a fix for this! Just left one minor comment so we know why the extension function is there in 6 months.

}
}

private fun TestModule.compilerModuleName(): String {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc comment clarifying the purpose of the function and the reason behind it :)

@jaschdoc

Copy link
Copy Markdown
Collaborator

Oh and one more thing: Could you also add the @Bug annotation to the test function in KSPUnitTestSuite linking it to #2964 so we know that it tests for that issue? See snippet:

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 this pull request may close these issues.

KSP 2.3.9 with Kotlin 2.4.0 fails to generate code

2 participants