Fix infinite recursion in get_ref_types