AST: improved handling of casts