add assertions after many unchecked dynamic casts

These were all reported by coverity, and indeed seem to have been
assumed to work without failing at runtime.