MIR validation: check switch_ty

This commit is contained in:
Ralf Jung 2020-06-21 18:24:51 +02:00
parent 3bfd0c9f07
commit 629722893c

View File

@ -121,7 +121,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
TerminatorKind::Goto { target } => {
self.check_edge(location, *target, EdgeKind::Normal);
}
TerminatorKind::SwitchInt { targets, values, .. } => {
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
let ty = discr.ty(&self.body.local_decls, self.tcx);
if ty != *switch_ty {
self.fail(
location,
format!(
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
ty,
switch_ty,
),
);
}
if targets.len() != values.len() + 1 {
self.fail(
location,