I'm only a Kotlin newbie, but after I had lost some time because of it, I was wondering... why the following code does not result in compilation error since the second return in hello()
or the print("ciao") in hello1
are clearly unreachable? (I'm confident that for other compilers, e.g. the Java compiler, this will be an error.)
fun main() {
print(hello())
print(hello1())
}
fun hello() : Boolean {
return true // 1st return, this is always returned
return false // 2nd return, unreachable
}
fun hello1() : Boolean {
return true // 1st return, this is always returned
print("ciao") // unreachable print
}
To be fair it gives a warning, but I'd like to have an error when such situations occur. Is there a way to make it an error?