[onnx] Do not deref nullptr in scalar type analysis (#50237)
Summary:
Apply a little bit of defensive programming: `type->cast<TensorType>()` returns an optional pointer so dereferencing it can lead to a hard crash.
Fixes SIGSEGV reported in https://github.com/pytorch/pytorch/issues/49959
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50237
Reviewed By: walterddr
Differential Revision: D25839675
Pulled By: malfet
fbshipit-source-id: 403d6df5e2392dd6adc308b1de48057f2f9d77ab