# Overload resolution ambiguity with suspend

**URL:** <https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485>\
**Category:** Uncategorized\
**Created:** [February 25, 2020, 6:12am UTC](https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485 "2020-02-25T06:12:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alamothe](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@alamothe](https://discuss.kotlinlang.org/u/alamothe)\
**Post date:** [February 25, 2020, 6:12am UTC](https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485/1 "2020-02-25T06:12:25Z")

</div>

Hello,  
I have the following code:

```auto
	suspend fun test(f: suspend () -> Unit) {
		f()
	}

	fun test(f: () -> Unit) {
		f()
	}
	
	fun main() {
		// Compile error below!
		test {
			delay(1000)
		}
	}

```

Unfortunately, this does not compile. The compiler is not able to deduce that the lambda must be suspendable, because it calls a suspending function.

In my case, I can’t have a single `inline` function, because of technical reasons that prevent inlining.

Is it possible to support this by the compiler?

Thanks

---

<div class="post-metadata">

**Author:** ![Beholder](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/beholder/32/2078_2.png) [@Beholder](https://discuss.kotlinlang.org/u/Beholder)\
**Post date:** [February 25, 2020, 8:41am UTC](https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485/2 "2020-02-25T08:41:58Z")

</div>

One possible solution is

```auto
    test(suspend {
        delay(1000)
    })

```

---

<div class="post-metadata">

**Author:** ![nickallendev](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@nickallendev](https://discuss.kotlinlang.org/u/nickallendev)\
**Post date:** [February 26, 2020, 8:39am UTC](https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485/3 "2020-02-26T08:39:52Z")

</div>

That only allows the suspend version to be called. The non suspend method can not be called still.

If you explained the reason you can’t inline, someone might be able to find a workaround.

Otherwise, different names may just be necessary unless you want to force callers to use some awkward work around like assigning their lambda to a variable before calling.

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [February 27, 2020, 1:29pm UTC](https://discuss.kotlinlang.org/t/overload-resolution-ambiguity-with-suspend/16485/4 "2020-02-27T13:29:24Z")

</div>

> [@alamothe](#):
>
> ```auto
> fun main() {
> // Compile error below!
> test { delay(1000) }
> }
> 
> ```

The main block does not create a coroutine context so calling the suspend version of test is invalid at this point.
