# Weird bug with inline functions

**URL:** <https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072>\
**Category:** Support\
**Created:** [November 28, 2020, 3:27am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072 "2020-11-28T03:27:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akasha](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Akasha](https://discuss.kotlinlang.org/u/Akasha)\
**Post date:** [November 28, 2020, 3:27am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072/1 "2020-11-28T03:27:29Z")

</div>

This is a minimal reproducible example.

```
import java.lang.IllegalStateException // Line 1

object BadLauncher {

	class A() {

	}

	inline fun A.b() {
		throw IllegalStateException()
	}

	@JvmStatic
	fun main(args:Array<String>) {
		A().b()
	}} // Line 16

```

Exceptions with:  
Exception in thread “main” java.lang.IllegalStateException  
at BadLauncher.main(main.kt:17)

There is no 17th line in this program. The stacktrace doesn’t seem to know where the exception came from.

It’s even weirder like this:  
import java.lang.IllegalStateException // Line 1

```
object BadLauncher {

	class A() {

	}

	inline fun A.b() {
		throw IllegalStateException()
	}

	@JvmStatic
	fun main(args:Array<String>) {
		A().b()
	}}

// I'm
// a
// little
// teapot // Line 21

```

Exceptions with:  
Exception in thread “main” java.lang.IllegalStateException  
at dev.fluffyderg.velandia.desktop.BadLauncher.main(BadLauncher.kt:22)  
It seems to just point to the end of the entire file no matter if it is in run or debug mode…

This is pretty annoying as i’m making use of this feature in more complicated functions and the stack trace will not take me to where the exceptions are originating from.

One such example is implementing the non-nullable exception throwing versions of min() and max() that were talked about during the Kotlin 1.4 presentations (rather than the minOrNull() and maxOrNull() methods which were the original min() and max() functions in 1.3). These functions are inline in the standard library \_Collections.kt class.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [November 28, 2020, 3:36am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072/2 "2020-11-28T03:36:07Z")

</div>

This is not a bug but an intended feature. inline functions have special line numbers outside of the file. This is necessary to support both the line number within the inline function as well as where the inline function is called from.  
Intellij Idea has a tool to resolve those stacktraces. I personally use idea so I don’t know what standalone tools exist if you don’t want to use idea but I’m sure there is one.

---

<div class="post-metadata">

**Author:** ![Akasha](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Akasha](https://discuss.kotlinlang.org/u/Akasha)\
**Post date:** [November 28, 2020, 3:40am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072/3 "2020-11-28T03:40:51Z")

</div>

I am using Idea, I tried both DCEVM 11 Runtime, OpenJDK 14 Runtime, and the included Jetbrains Java 11 runtime and they all have the same error. I can see Idea has options to go to the inline function body and call site but they both do not do anything when clicked.

---

<div class="post-metadata">

**Author:** ![Akasha](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@Akasha](https://discuss.kotlinlang.org/u/Akasha)\
**Post date:** [November 28, 2020, 3:48am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072/4 "2020-11-28T03:48:46Z")

</div>

strange… all of a sudden the stacktrace tool started working after i tried a real test with a lambda parameter, compiling and then reverting. I probably forgot to compile after switching runtimes or something.

Yeah i’m pretty sure it has something to do with DCEVM 11 (a runtime for hot swapping classes at runtime). Afrter compiling with IDEA-included Runtime it the tool seems to be working

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [November 28, 2020, 3:53am UTC](https://discuss.kotlinlang.org/t/weird-bug-with-inline-functions/20072/5 "2020-11-28T03:53:16Z")

</div>

We have all been there. I just love it when I can get something to work ask someone else for help and they do the exact same thing I tried but it works for them. Sometimes all you need to do is ask someone else and everything works like magic 😉
