Fixed a problem in Type.cast()