diff --git a/src/valid/function.rs b/src/valid/function.rs index 14068e3e4..70980e125 100644 --- a/src/valid/function.rs +++ b/src/valid/function.rs @@ -108,6 +108,8 @@ pub enum FunctionError { ConflictingSwitchCase(i32), #[error("Multiple `default` cases are present")] MultipleDefaultCases, + #[error("The last `switch` case contains a `falltrough`")] + LastCaseFallTrough, #[error("The pointer {0:?} doesn't relate to a valid destination for a store")] InvalidStorePointer(Handle), #[error("The value {0:?} can not be stored")] @@ -469,6 +471,17 @@ impl super::Validator { } } } + if let Some(case) = cases.last() { + if case.fall_through { + return Err(FunctionError::LastCaseFallTrough.with_span_static( + case.body + .span_iter() + .next() + .map_or(Default::default(), |(_, s)| *s), + "bad switch arm here", + )); + } + } let pass_through_abilities = context.abilities & (ControlFlowAbility::RETURN | ControlFlowAbility::CONTINUE); let sub_context =