Small thing that could be useful for functional ap...
# language-proposals
n
Small thing that could be useful for functional approach: recognize "exit" type and ignore recursive calls when type-checking tailrec function return type. In this example function terminates only with returned integer:
Copy code
tailrec fun numbersum(i: Int, acc: Int=0) = if (i == 0) acc else numbersum(i - 1, acc + i)
Currently Kotlin compiler throws out exception:
Copy code
ERROR: Rewrite at slice COMPILE_TIME_VALUE key: INTEGER_CONSTANT old value: IntegerValueType(1)@57604788 new value: IntegerValueType(1)@527224921
...
ERROR: Exception while analyzing expression at (17,41) in /home/elviss/tmp/inlinetest/src/main/kotlin/com/mycompany/myapp/Problem.kt:
if (i == 0) acc else numbersum(i - 1, acc + i)
...
and Idea suggests that easiest way to fix expression is to explicitly set return type of function.