From 56fa2b6803f12f833e53d2245a27b4c94804df75 Mon Sep 17 00:00:00 2001 From: lyken Date: Thu, 27 Jun 2024 16:59:35 +0800 Subject: [PATCH] core: fix crash on iterating over non-iterables a --- nac3core/src/typecheck/type_inferencer/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 4a991654..f879650f 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -248,7 +248,17 @@ impl<'a> Fold<()> for Inferencer<'a> { TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => { todo!() } - _ => unreachable!(), + _ => { + // User is attempting to use a for loop to iterate + // over a value of an unsupported type. + + let iter_ty = iter.custom.unwrap(); + let iter_ty_str = self.unifier.stringify(iter_ty); + return report_error( + format!("'{iter_ty_str}' object is not iterable").as_str(), + iter.location, + ); + } }; self.unify(list_like_ty, iter.custom.unwrap(), &iter.location)?; }