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

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

1 participant