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] KSValueParameterImpl changes field isVal if class defined in library #2348

Open
oscarthecat opened this issue Feb 24, 2025 · 0 comments
Milestone

Comments

@oscarthecat
Copy link

oscarthecat commented Feb 24, 2025

kotlin version 2.1.0
ksp version 2.1.0-1.0.28

we have a module1/ConsoleLens.kt, in which we have a

@LensForType(type = Console::class, intoPackage = "com.foobar.blens.test")
interface ConsoleLens

we try to handle @LensForType this annotation in out ksp. It refer another Console class which is defined in module2/Console.kt like

data class Console(
    val brand: String,
    val type: String,
) {
    companion object
}

when our ksp runs we check Console class should be data class and all params in primary constructor should be val, but it failed when using ksp2, while it does work when using ksp1.

In ksp2 if Console.kt is also defined in module1(as -source-roots like ConsoleLens.kt), it also works. It failed to our check when Console.kt is defined in -libraries as a klib, this happen both via gradle build and command line build.

After debug isVal we find in KSValueParameterImpl.kt

    override val isVal: Boolean
        get() = (ktValueParameterSymbol.psi as? KtParameter)?.let { it.hasValOrVar() && !it.isMutable } ?: false

ktValueParameterSymbol (came from -libraries klib) it self isVal is true, but ktValueParameterSymbol.psi is null so finally it returns false.

Any way to get ktValueParameterSymbol.psi non null? or any change should we apply to out ksp2 command? Thanks a lot.

ps out ksp2 command is like

-cp
symbol-processing-common-deps.jar:symbol-processing-aa.jar:symbol-processing-api.jar:artifacts/org.jetbrains.kotlin/kotlin-stdlib/2.1.0/processed_kotlin-stdlib-2.1.0.jar:artifacts/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.6.4/processed_kotlinx-coroutines-core-jvm-1.6.4.jar
com.google.devtools.ksp.cmdline.KSPCommonMain
-module-name=lens_test_library_ksp2_common
-project-base-dir
bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated
-source-roots
srcs/base/blens/sample/module/src/commonMain/kotlin/com/foobar/blens/ConsoleLens.kt (//Use Console class)
-output-base-dir=bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated
-caches-dir=bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated/caches
-class-output-dir=bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated/classes
-kotlin-output-dir=bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated/kotlin
-resource-output-dir
bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module/lens_test_library_ksp2_common_generated/resources
-language-version=2.0
-api-version=2.0
-targets=common
-libraries=bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/sample/module-for-dep/console.klib(// Defines Console class):bazel-out/darwin_arm64-fastbuild/bin/srcs/base/blens/core/core.klib
out_ksp_processor.jar
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

No branches or pull requests

2 participants