fix #8853

See discussion in #8853, current recursion check fails for staged function.
Merge pull request #9440 from JuliaLang/jh/recursivestagedfix

fix #8853