Be careful that you are not mistaken how the @tailrec annotation @tailrec - this does not force the compiler to optimize the function in a tail-recursive manner (the compiler will alwasys do this optimization anyway if it can).
Most likely, this is just a marker that you can use to tell the compiler: "I think this function was successfully written in a tail recursive manner, tell me if you can optimize it that way."
That is, use it where you want to be sure that you have correctly written a function designed to eliminate the tail, and the compiler can indicate when you make a mistake.
Does this mean what you see? I cannot say anything useful without seeing the sample code in which you used the annotation.
source share