Fix bug where CAS returned the wrong type if the old and new types are different.