Add assertion and fix AST identity that had broken by template instantiation