# Why doesn't suspend function support overloading?

**URL:** <https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456>\
**Category:** Support\
**Created:** [October 30, 2024, 1:15pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456 "2024-10-30T13:15:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thd0427](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@thd0427](https://discuss.kotlinlang.org/u/thd0427)\
**Post date:** [October 30, 2024, 1:15pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/1 "2024-10-30T13:15:57Z")

</div>

The following code is

A compilation error occurs with the message

> Conflicting overloads: fun func(): Unit

```auto
suspend fun func() {

}

fun func() {

}

```

But when you decompile, the two functions are clearly different.

```auto
@Nullable
   public static final Object func(@NotNull Continuation $completion) {
      return Unit.INSTANCE;
   }

public static final void func() {
   }

```

The suspend method has a Continuation object declared as a parameter.  
If so, isn’t there a distinction between non-suspend methods and method signatures?

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [October 30, 2024, 1:21pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/2 "2024-10-30T13:21:40Z")

</div>

It’s because the two declarations are conflicting when called. If you call `foo()` inside a `suspend` function, which should that call resolve to? The question is ambiguous enough that the compiler throws its hands up and just tells you to deal with it

---

<div class="post-metadata">

**Author:** ![thd0427](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@thd0427](https://discuss.kotlinlang.org/u/thd0427)\
**Post date:** [October 30, 2024, 3:20pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/3 "2024-10-30T15:20:44Z")

</div>

Thank you for your reply.  
If you think about it from the Kotlin compiler’s perspective, it was a problem that could be easily solved 🙂

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [October 30, 2024, 4:46pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/4 "2024-10-30T16:46:04Z")

</div>

Why would you even need this? What’s a legitimate use-case?

---

<div class="post-metadata">

**Author:** ![kyay10](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@kyay10](https://discuss.kotlinlang.org/u/kyay10)\
**Post date:** [October 30, 2024, 4:56pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/5 "2024-10-30T16:56:36Z")

</div>

Of course it can be easily solved, and in fact Kotlin has made some ambiguity-resolving choices in other areas, but this one was deemed too semantically ambiguous for the person reading and writing the code

---

<div class="post-metadata">

**Author:** ![ebrowne72](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@ebrowne72](https://discuss.kotlinlang.org/u/ebrowne72)\
**Post date:** [October 30, 2024, 9:51pm UTC](https://discuss.kotlinlang.org/t/why-doesnt-suspend-function-support-overloading/29456/6 "2024-10-30T21:51:36Z")

</div>

I don’t think it’s easily solved. If I call `func()` from within a coroutine, which version should be called? Both are perfectly valid function calls in that context, so the compiler has no idea which one I want.
