kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
183 stars 12 forks source link

verifying with isAny() causes ClassCastException on JS target #62

Open ygnessin opened 1 year ago

ygnessin commented 1 year ago

The following test passes both on JVM and iOS targets:

        verifyWithSuspend {
            myMock.myFunction(isAny())
        }

But when targeting JS, it crashes with this exception:

ClassCastException:
    at <global>.THROW_CCE(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/runtime/hacks.kt:23)
    at REDACTED.protoOf.get_94x98z(kotlin/REDACTED-test.js:614)
    at slambda_3.protoOf.doResume_5yljmg(REDACTED.kt:333)
    at slambda_3.protoOf.invoke_uezeh0(kotlin/REDACTED-test.js:4554)
    at 2.block(kotlin/REDACTED-test.js:4632)
    at 2.protoOf.doResume_5yljmg(/System/Volumes/Data/home/runner/work/MocKMP/MocKMP/mockmp-runtime/src/commonMain/kotlin/org/kodein/mock/Mocker.kt:253)
    at Mocker.protoOf.verifyWithSuspend_wm0mpz(kotlin/Kosi-MocKMP-mockmp-runtime.js:2140)
    at REDACTED.verifyWithSuspend_wm0mpz(/System/Volumes/Data/home/runner/work/MocKMP/MocKMP/test-helper/mockmp-test-helper/src/commonMain/kotlin/org/kodein/mock/tests/ITestsWithMocks.kt:44)
    at REDACTED.verifyWithSuspend$default_fl21z0(kotlin/Kosi-MocKMP-mockmp-test-helper.js:75)
    at slambda.protoOf.doResume_5yljmg(REDACTED/src/commonTest/kotlin/REDACTED.kt:329)
    at slambda.protoOf.invoke_qflhgo(kotlin/REDACTED-test.js:4846)
    at slambda.$testBody(kotlin/REDACTED-test.js:4956)
    at slambda.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:314)
    at slambda.protoOf.resumeWith_7onugl(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/commonMainSources/libraries/stdlib/src/kotlin/util/Standard.kt:55)
    at slambda.protoOf.resumeWith_s3a3yh(kotlin/kotlin-kotlin-stdlib-js-ir.js:24676)
    at DispatchedContinuation.protoOf.run_mw4iiu(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/commonMainSources/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:45)
    at StandardTestDispatcherImpl.protoOf.processEvent_iukd42(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestDispatcher.kt:28)
    at TestCoroutineScheduler.protoOf.tryRunNextTaskUnless_d4q0a1(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestCoroutineScheduler.kt:103)
    at slambda_1.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-test/common/src/TestBuilders.kt:320)
    at slambda_1.protoOf.invoke_d6gbsu(kotlin/kotlinx.coroutines-kotlinx-coroutines-test-js-ir.js:356)
    at <global>.l(kotlin/kotlinx.coroutines-kotlinx-coroutines-test-js-ir.js:433)
    at _no_name_provided__qut3iv_8.protoOf.doResume_5yljmg(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/src/kotlin/coroutines_13/IntrinsicsJs.kt:163)
    at _no_name_provided__qut3iv_8.protoOf.resumeWith_7onugl(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/commonMainSources/libraries/stdlib/src/kotlin/util/Standard.kt:55)
    at _no_name_provided__qut3iv_8.protoOf.resumeWith_s3a3yh(kotlin/kotlin-kotlin-stdlib-js-ir.js:24676)
    at DispatchedContinuation.protoOf.run_mw4iiu(REDACTED/build/compileSync/js/test/testDevelopmentExecutable/kotlin/commonMainSources/libraries/stdlib/src/kotlin/coroutines/Continuation.kt:45)
    at ScheduledMessageQueue.protoOf.process_mza50i(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/JSDispatcher.kt:155)
    at <global>.<unknown>(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/js/src/JSDispatcher.kt:19)
    at <global>.processTicksAndRejections(node:internal/process/task_queues:78)

If I replace isAny() with a real argument, then the test passes on all targets. But I'd like to be able to use isAny() without my JS tests crashing.

Thank you!

SalomonBrys commented 1 year ago

I've tried to replicate the bug with this test but the test runs fine. What is the type of the parameter ? Can you create a test demonstrating the issue ?

ygnessin commented 1 year ago

Thanks for looking into this @SalomonBrys

In my case, the type of the parameter was a Data Class that looked like this:

@Serializable
public data class MyDataClass(
    val uuid: String,
    val flag: Boolean,
)

Strangely enough, in the same test there are other verifications on different data classes that do work with isAny(). So maybe there is something specific about that data class's structure or parameters that causes the problem.

I will try to create an isolated test that demonstrates this issue. Thanks!

EDIT: I tried my best but my example test passes. There must be something very specific about my other test that fails when I switch to isAny(). I will update you if I discover anything more