In this simple code example ...
fun testLocalFunctions() {
aLocalFun()
fun aLocalFun() {}
aLocalFun()
}
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?)
source
share