# Weird errors with return inside lambda

**URL:** https://discuss.kotlinlang.org/t/weird-errors-with-return-inside-lambda/1661
**Category:** Support
**Created:** [May 10, 2016, 6:11pm UTC](https://discuss.kotlinlang.org/t/weird-errors-with-return-inside-lambda/1661 "2016-05-10T18:11:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)
#### Post date: [May 10, 2016, 6:11pm UTC](https://discuss.kotlinlang.org/t/weird-errors-with-return-inside-lambda/1661/1 "2016-05-10T18:11:37Z")

</div>

So in Kotlin 1.0 I was getting a runtime error on some code. Here is a stripped down version of my code that still demonstrates the problem:

private fun foo()  
= File(“foo”).run()  
{  
return arrayOf(1, 2)  
}

This failed at runtime saying it could not cast the array to java.lang.Void, but it gave a stack trace line number that did not exist so I had no idea where the actual error was.

To try to diagnose it I tried switching to 1.0.2 eap and it fails at compile time with:

```
'Nothing' return type needs to be specified explicitly

```

The line number is on the blank line before the function and the message was not very helpful but I was able to deduce that the error was due to the return statement. If I remove the return and just have the expression as the last line it works.

So I know the fix, just looking for some pointers to documentation on the thinking here regarding return statements inside of lambdas and is this a bug?

---

<div class="post-metadata">

### Author: ![Dittert](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dittert/32/1736_2.png) [@Dittert](https://discuss.kotlinlang.org/u/Dittert)
#### Post date: [May 10, 2016, 8:27pm UTC](https://discuss.kotlinlang.org/t/weird-errors-with-return-inside-lambda/1661/2 "2016-05-10T20:27:12Z")

</div>

There’s something in the chapter about inline functions: [Non-local returns](https://kotlinlang.org/docs/reference/inline-functions.html#non-local-returns).

There are already an issue that might be related to this: [KT-10717](https://youtrack.jetbrains.com/issue/KT-10717). [KT-6295](https://youtrack.jetbrains.com/issue/KT-6295) is the change that required `Nothing` to be declared explicitely.
