Skip to content

[KSP2] getJvmName for internal method did not sanitize java identifiers #2413

@acejingbo

Description

@acejingbo

For internal methods "getInternalProp" in a module named "lib-xyz",

  • Kotlin compiler jvm name is: getInternalProp$lib_xyz.
  • KSP2 getJvmName returned: getInternalProp$lib-xyn.

Notice "-" is a java identifier, so kotlin compiler sanitize it here https://github.com/JetBrains/kotlin/blob/684e1b86eec86497829abcd2f1523ba9b5645bb4/analysis/light-classes-base/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt#L199
Not sanitizing a java identifier and generating code with java identifier in method call would cause
(1) mismatch with real jvm name so fail to call the method
(2) fail with things like

error: not a statement
    MyClass.INSTANCE.getInternalProp$lib-xyn

Notice this new since kotlin 2.1.0. I did not have this problem in 2.0.20-1.0.24

Repro

acejingbo@44f014d
run KSPAATest.testMangledNames
see it fail with

Image

(Sorry i couldn't create a counter example in ksp1 test, as KSP1 test use - for target platform)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions