https://kotlinlang.org logo
v

vektory79

02/16/2016, 4:14 PM
One more (bug?): Due to documentation (https://kotlinlang.org/docs/reference/functions.html), I can return from external function by returning in inner function. But it's don't compile:
Copy code
fun reachable(from: String, to: String): Boolean {
    val visited = HashSet<String>()
    fun dfs(current: String) {
        // here we return from the outer function:
        if (current == to) return@reachable true // << ERROR: 'return' is not allowed here
        // And here -- from local function:
        if (!visited.add(current)) return
        for (v in current.split('.'))
            dfs(v)
    }

    dfs(from)
    return false // if dfs() did not return true already
}