Kotlin.JS lambda does not compile, fun does

Hi

There is a strange compiler behavior that I don’t understand:

import kotlin.js.Date
import org.w3c.dom.Document

private external val document: Document = definedExternally

fun now(locale: String = "de-DE") =
        Date().toLocaleTimeString(locale)

fun main() {

    println("Hello Kotlin")
    document.title = now("en-US")

    fun onClick(e: dynamic) {
        e.target.innerText = now()
    }

    val obj: dynamic = document.getElementById("_mainDIV")
    obj.innerText = "Hello Kotlin"
    // does complie & run
    // obj.addEventListener("click", ::onClick)

    // does not compile ?
    obj.addEventListener("click"){ e: dynamic ->
        e.target.innerText = now()
    }
}

Resulting compiler error is:

Task :compileKotlin2Js FAILED
e: Y:\myWebTest\kotlin\src\main.kt: (38, 9): Expected a value of type dynamic

Your lambda has to return a value and e.target.innerText = now() is not an expression.
Try this:

obj.addEventListener("click") { e: dynamic ->
    e.target.innerText = now()
    Unit
}

Does compile & run -thank you.
But I still can’t guess what the point is.
The ::onClick function also has no return / is Unit.
Thus, the compiler amends the term automatically -
and doesn’t a lambda has such a complement?

Inferred type of the handler is actually (dynamic) -> dynamic, not (dynamic) -> Unit. So you cannot omit return value.