I'm running into an error when using a while loop ...
# announcements
a
I'm running into an error when using a while loop in a lambda:
Copy code
// works, returns 1
fun foo(): Int {
    while (true) return 1
}

//Type mismatch: inferred type is Unit but Int was expected
fun bar(): () -> Int = l@{
    while (true) return@l 1
}

// works, returns 1, but results in 'Warning: Unreachable code'
fun baz(): () -> Int = l@{
    while (true) return@l 1
    2
}
I understand what's happening, but is there a documented reason that
bar
wouldn't compile, or should I file an issue?