Error:(107, 46) Kotlin: Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly
snowe
12/13/2019, 5:34 PM
on the last recursive part. I'm not sure how to resolve it, i've tried casting n to Int there, but it does nothing...
c
Casey Brooks
12/13/2019, 5:36 PM
It’s because the function is declared as an expression, but it cannot resolve the expression without knowing the type of the function. You will have to move the expression into the function body
Copy code
fun a(n: Int): Int {
return if (n/3-2 <= 0) 0 else n/3-2 + a(n/3-2)
}
s
snowe
12/13/2019, 5:36 PM
Ah, Ok, so I can resolve it just by specifying a function type.