Replacing auto cast with ast-based approach