fix PR9210 by implementing some type legalization logic for