Skip to content

KSP 2.3.9 with Kotlin 2.4.0 fails to generate code #2964

@SimonMarquis

Description

@SimonMarquis

This can be triggered while using Dagger/Hilt, on

// my-project/features/Foo/impl/src/kotlin/.../FooModule.kt
@InstallIn(SingletonComponent::class)
internal object FooModule {
    @Provides
    internal fun providesMyDependency(...) = ...
}

Here is the corresponding stacktrace it will generate.

e: [ksp] java.lang.IllegalArgumentException: Can't escape identifier `FooModule_ProvidesMyDependency$my_project_feature_Foo:implFactory` because it contains illegal characters: :

The error goes away when I remove the internal modifier on providesMyDependency.

This appears to be linked with this recent change in Kotlin 2.4.0:

https://kotlinlang.org/docs/whatsnew24.html#consistent-module-names-across-platforms
Prior to Kotlin 2.4.0, default module names differed across platforms. This inconsistency could cause naming conflicts and resolution issues. Kotlin 2.4.0 standardizes the default names to {group}:{project_name} across all platforms.

Manually overriding the moduleName fixes the issue, but I suppose KSP (or dagger, I'm not sure whose responsibility it is) should handle these invalid chars that are now standardized by Kotlin 2.4.0 before using them through kotlinpoet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2affects usability but not blocks users

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions