Why not error


#1
class HTML {
    fun body() {}
}

fun aaa() {}

fun html(foo: HTML.() -> Unit): HTML {
    val html= HTML()
    html.foo()
   return html
}

fun main(args: Array): Unit {
    html{ aaa() } //aaa not HTML object receive function, why not error?
}

#2

Here’s your code properly indented :slight_smile::

class HTML {
    fun body() {}
}

fun aaa() {}

fun html(foo: HTML.() -> Unit): HTML {
    val html= HTML()
    html.foo()
   return html
}

fun main(args: Array): Unit {
    html{ aaa() } //aaa not HTML object receive function, why not error?
}

If you’re looking for help, I recommend that you post readable code :wink:

Now for the answer: The aaa function is simply called. You can call any non-member function from “within” an object.


#3

thanks.


#4

Forbidding aaa() in your example is equal to forbidding println() and ANY OTHER top-level function and constructor, which is hardly practical.