Make casts work again properly (bug #3155)