Fix #1342: Handle value classes for type parameters and don't unbox value classes returned as interface/supertype#1442
Conversation
| if (!resultType.isValue_safe) { | ||
| return this | ||
| } | ||
|
|
There was a problem hiding this comment.
I reworked the function to remove duplication and hopefully improve clarity.
.gitignore
Outdated
|
|
||
| .gradle/ | ||
|
|
||
| .kotlin/ |
There was a problem hiding this comment.
Created by Kotlin Gradle Plugin during tests.
| assertEquals(JavaEnum.A, result) | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Added several test cases covering value class handling.
|
I see there was a build failure: https://github.com/mockk/mockk/actions/runs/18830786451/job/53742959648?pr=1442#step:9:630 I'm not particularly familiar with Android development. Is this something I need to fix in my PR, or an issue with the build infrastructure? |
|
@ianbrandt , can you please rebase on top of the master branch? I should have fixed the build failure. |
@Raibaz, Done. Thank you for considering this PR. Additional notes: As I dug into this with test cases, I realized the issue I described in #1342 (comment) turned out to be a separate, much simpler to fix bug than the generics issue originally reported by @micheljung. I’ve attempted to fix both in this PR. Admittedly, not being deeply familiar with MockK or Kotlin value class internals, I leaned on Junie quite a bit to help develop the code and documentation for the cached "*unbox-impl" |
|
Thanks for this! I like the test coverage particularly. I agree the KDoc and comments in ValueClassSupport.kt are a bit too much, can you clean them up a bit? |
You got it. Will do. |
91c0c79 to
b4bd8ad
Compare
|
@Raibaz, I finally got a chance to clean up the KDoc and inline comments for this change. I also rebased the changes onto the latest master (hence the force push to this branch). Let me know if you see anything else that needs fixing. |
|
Can you also please run Thanks! |
|
Done. I wasn't familiar with Spotless. I'll be sure to run that after any other changes going forward. Thanks! |
|
Looks like there are some test failures in older Kotlin versions and in instrumented tests. Can you PTAL? Thanks! 🙏 |
…ed as their interface or supertype to avoid a `ClassCastException` (fixes mockk#1342).
…g of value classes.
…Plugin temporarily during `gradlew check`).
…operty types, and added KDoc.
…ockk#1308 to ensure those fixes are preserved by the mockk#1342 changes.
…y version to align with the `io_mockk_kotlin_version` Gradle project property, if set.
…to support backwards compatibility with Android API level 21.
I believe the client test failures with earlier versions of Kotlin were due to them being run with the latest Kotlinx Coroutines version, which is not that backwards compatible. I believe any I believe the instrumented tests were failing because they require compatibility with API level 21, and I had used P.S. I also rebased against current master and checked |
|
Thanks a lot for all the follow ups, this looks very clean now! 🙏 |
Handle generic type parameters of value classes. Don't unbox value classes that are returned as their interface or supertype to avoid a
ClassCastException. See added KDoc for details. Fixes #1342.