Is any difference between lambda expression and anonymous function?


I personally assume that lambda expression and anonymous function share the same implementation, and the snippet below confuses me quite a lot.

// this compiles
inline fun bar(crossinline f: () -> Int) = { f() }

// this fails, error message says that such construction
// is not yet supported to be inlined
inline fun foo(crossinline f: () -> Int) = fun () = f()

What’s the problem that foo should be prevented to be compiled?


There is no fundamental problem; the message is basically a bug in the Kotlin compiler. Please file a YouTrack issue, and we’ll fix it.