Use cast<> instead of unchecked dyn_cast<>