Recursion guard for collectGenericSubstitutions