Fix a bug in type substitution