From 10703472035b3f4f0810ed85f47f9a1ddbd0a319 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sun, 5 May 2024 13:10:30 +0200 Subject: [PATCH] Panic when encountering unknown generics. This should not happen; if it does, it's an error from the type-checker. So instead of silently swallowing the error and adopting a behavior which is only _sometimes_ right, it is better to fail loudly and investigate. --- crates/aiken-lang/src/tipo.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/aiken-lang/src/tipo.rs b/crates/aiken-lang/src/tipo.rs index 68040384..f29257c3 100644 --- a/crates/aiken-lang/src/tipo.rs +++ b/crates/aiken-lang/src/tipo.rs @@ -819,9 +819,12 @@ pub fn find_and_replace_generics( mono_types: &IndexMap>, ) -> Rc { if let Some(id) = tipo.get_generic() { - // If a generic does not have a type we know of - // like a None in option then just use same type - mono_types.get(&id).unwrap_or(tipo).clone() + mono_types + .get(&id) + .unwrap_or_else(|| { + panic!("Unknown generic id {id:?} for type {tipo:?} in mono_types {mono_types:#?}"); + }) + .clone() } else if tipo.is_generic() { match &**tipo { Type::App {