Kotlinx.coroutines: Error when call local suspend function with default param without arguments

Created on 25 Feb 2020  路  4Comments  路  Source: Kotlin/kotlinx.coroutines

Hi,

I found weird behavior, which I'd call a bug: local suspend function with default param crashes in runtime if no argument is provided.

Code snippet for that is:

class LocalSuspend {

    @Test
    fun test() {
        val latch = CountDownLatch(1)

        suspend fun localSuspendDefault(value: String = "local default"): String {
            delay(100)
            return "localSuspendDefault: $value"
        }

        CoroutineScope(Job()).launch {
/*
memberSuspendWithDefault: default
 */
            println(memberSuspendWithDefault())

/*
localSuspendDefault: new
 */
            println(localSuspendDefault("new"))

            /*
Exception in thread "DefaultDispatcher-worker-1 @coroutine#1" java.lang.NoSuchMethodError: com.example.testflow.LocalSuspend$test$1.invoke$default(Lcom/example/testflow/LocalSuspend$test$1;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
  at com.example.testflow.LocalSuspend$test$2.invokeSuspend(LocalSuspend.kt:38)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
             */
            println(localSuspendDefault())

            latch.countDown()
        }

        latch.await()
    }

    private suspend fun memberSuspendWithDefault(value: String = "default"): String {
        delay(100)
        return "memberSuspendWithDefault: $value"
    }
}

Here execution tests are shown with result printed (on top).

For member suspending function with default param without argument it works fine.

For local suspending function with default param with argument it works fine.

But for local suspending function with default param with no argument it has a java.lang.NoSuchMethodError.

I expect local function to work same as member suspending function with default param and not crash.

Thank you

All 4 comments

It is a compiler bug.

Vote here: https://youtrack.jetbrains.com/issue/KT-27449

Hi, @fvasco
Thank you for your reply

Should I close this issue then?

Yes @krossovochkin, you should.
It is the right issue on the wrong tracker ;)

Can confirm it is a compiler bug, so please keep track of it using youtrack.
Thanks for the report!

Was this page helpful?
0 / 5 - 0 ratings