fix #8853

See discussion in #8853, current recursion check fails for staged function.