Been a while since I last used it but there is @tailrec in Scala. The compiler does enforce it and optimize the resulting bytecode.