Why following code
def doSomething() = \"Something\"
var availableRetries: Int = 10
def process(): String = {
while (true) {
availableRetries -= 1
tr
The compiler isn't smart enough to know that you can't exit the while loop, unfortunately. It's easy to trick, though, even if you can't sensibly generate a member of the return type--just throw an exception.
def process(): String = {
while (true) {
...
}
throw new Exception("How did I end up here?")
}
Now the compiler will realize that even if it escapes the while loop, it can't return a value there, so it doesn't worry that the while loop has return type Unit
(i.e. does not return a value).