The compiler is lying to you.
It's the nested return statements in your function. Declare a var at the top of the function, then instead of having RETURNS inside your IF statements, set the value of the var.
Then, at the end of the routine, return your var.
I've had this issue myself numerous times - it's a fault with ...