Resolve type variables when checking casting to char

Fix #9918.