Local Kotlin functions must be declared before use.

In this simple code example ...

fun testLocalFunctions() {
    aLocalFun() //compiler error: unresolved reference at aLocalFun
    fun aLocalFun() {}
    aLocalFun() //no error
}

Elsewhere in the language, the use of a function before definition is allowed. But for local functions this is not so. Referring to the Kotlin Language Specifics , the Local Functions section is still marked “TODO”.

Since this type of restriction is not satisfied for other types of functions (top-level functions and members), is this an error?

(Of course, local variable declarations should appear before use, so the same restriction on local functions is not unreasonable. Is there a final, preferably authoritative source document that discusses this behavior?)

+4
source share
1

, .

(, ) , . , , , (, ) , , , ,

, , ​​ , , ​​ : .

+4

Source: https://habr.com/ru/post/1686718/


All Articles