Fixed a crash when instantiating template types