fix #8768, make `isimmutable` a generic function