Hi! I think I’ve found a bug in `kotlin.reflect` a...
# kontributors
w
Hi! I think I’ve found a bug in
kotlin.reflect
and I want to contribute. I did some research and here’s what I found. Calling
metod.kotlinFunction
on a method that is a suspend function with inline class as a return type results in an error. It happens exactly in InlineClassAwareCaller.kt#L100. It is similar to KT-34024 , but it’s not exactly it. I went through the code and now I have a working minimal setup that reproduces the problem and some ideas how to fix it. I’d like to apply my ideas, starting with writing failing tests. I tried to find out how to write one, but I couldn’t find any instructions for that. I checked what git-blame says about the file and I found a commit which modifies the code and adds some tests. The commit adds, for example, compiler/testData/codegen/box/reflection/callBy/inlineClassDefaultArguments.kt, and, in the beginning of the file, there is:
Copy code
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
I found another one with:
Copy code
// TARGET_BACKEND: JVM
// WITH_REFLECT
// WITH_COROUTINES
They seem to be instructions for a tool used in tests. Do you have any manual for it? Eg what options are available? Is it a good idea if I try to mimic what the linked commit does? I mean, is it sufficient to add *.kt file in the compile/testData/codegen directory and call
./gradlew coreLibTests
? Thank you :)
u
Hi! Regarding this specific issue, I’ve been working on it since yesterday (see the state “In progress”) and have a fix already. So please don’t look into it. But in general, kotlin-reflect is being tested as a part of the compiler tests. Compiler tests are generated with the “Generate compiler tests” IDEA run configuration, or
generateTests
Gradle task. You can simply add a test file (in this case, to
compiler/testData/codegen/box/reflection/...
) and regenerate tests, after which you’ll see a bunch of new tests added. The main one of those would be in
BlackBoxCodegenTestGenerated
, this is the (old) JVM backend used in Kotlin 1.4. Other tests are checking other parts of the compiler, which you can see by their names (new frontend, JS backends, etc.). For JVM-specific reflection tests, you need to have
TARGET_BACKEND: JVM
and
WITH_REFLECT
directives.
Regarding the binary compatibility validator test failure, if you do care about those, make sure you have `JDK_16`/`JDK_17`/`JDK_18`/`JAVA_HOME` environment variables set up correctly as explained in the ReadMe. But these tests don’t check anything related to kotlin-reflect, so you can ignore them. Most of the reflection tests are in
BlackBoxCodegenTestGenerated.Reflection
.
w
Thank you for writing back, @udalov! I’m happy you have a fix for it. On the other hand, it’s so unfortunate that I didn’t write earlier, because I was looking into it for a couple of days and now I missed the opportunity of the first contribution 😢
I’ll watch the issue and test my case with your fix.
u
Oh, contributions to kotlin-reflect are still very welcome! (We’ve been busy with the compiler rewrite lately, so didn’t have enough time to fix issues there.) I’ll be glad to help you if you encounter any other issues and would like to fix them.
👍 1
w
@udalov I’ve taken a look at the fix you prepared in InlineClassAwareCaller and it is essentially the same thing I was trying to test 🙂
👍 1